zsh-users
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: One more heap optimization trick for zsh < 5.2
Date: Sat, 11 Jun 2016 09:40:46 +0200	[thread overview]
Message-ID: <CAKc7PVDzNgEti5MfzgmaQ6hRHhqiQ-E2na-38tNak3zh_141Lg@mail.gmail.com> (raw)
In-Reply-To: <160610203056.ZM10515@torch.brasslantern.com>

[-- Attachment #1: Type: text/plain, Size: 2686 bytes --]

On 11 June 2016 at 05:30, Bart Schaefer <schaefer@brasslantern.com> wrote:
> This means that it has to be something that's happening in the loop
> inside the n-list function, affecting every iteration.

Agree

> Consequently it must be one of n-list-input or n-list-draw, both of
> which are declared with [the shadowed] autoload inside n-list itself.
> Something about nesting calls to --zplg-reload-and-run is causing
> the issue.

Hmm didn't thought about that, about nesting

> It might have something to do with retaining the old copy
> of the function body until the call stack unwinds and it can safely
> be freed; a large value for $argv would therefore also hang around
> (two copies of it) for all of that time.

That's apparently a hit. I attach two test files. First doesn't pass
anything to sub-function:

# ./aload.zsh2.txt
Normal autoload:
( aload_fun_main; )  10,91s user 0,23s system 99% cpu 11,156 total
Special autoload:
( aload_fun_main; )  9,54s user 0,23s system 99% cpu 9,792 total
More special autoload:
( aload_fun_main; )  9,15s user 0,22s system 99% cpu 9,393 total

# ./aload.zsh2.txt
Normal autoload:
( aload_fun_main; )  8,85s user 0,22s system 99% cpu 9,103 total
Special autoload:
( aload_fun_main; )  8,15s user 0,23s system 99% cpu 8,405 total
More special autoload:
( aload_fun_main; )  9,36s user 0,22s system 99% cpu 9,596 total

# ./aload.zsh2.txt
Normal autoload:
( aload_fun_main; )  10,22s user 0,22s system 99% cpu 10,454 total
Special autoload:
( aload_fun_main; )  9,73s user 0,22s system 99% cpu 9,971 total
More special autoload:
( aload_fun_main; )  8,02s user 0,22s system 99% cpu 8,262 total

(I wonder why the varying). Second one passes long array to sub-function:

# ./aload.zsh3.txt
Normal autoload:
( aload_fun_main; )  11,58s user 0,25s system 99% cpu 11,847 total
Special autoload:
( aload_fun_main; )  10,77s user 0,25s system 99% cpu 11,042 total
More special autoload:
( aload_fun_main; )  18,38s user 0,27s system 99% cpu 18,679 total

# ./aload.zsh3.txt
Normal autoload:
( aload_fun_main; )  10,99s user 0,25s system 99% cpu 11,270 total
Special autoload:
( aload_fun_main; )  10,71s user 0,26s system 99% cpu 10,984 total
More special autoload:
( aload_fun_main; )  19,02s user 0,28s system 99% cpu 19,329 total

> Incidentally, the way n-list is currently written, it will re-autoload
> those functions and re-create all the _nlist_* helpers EVERY TIME IT
> IS RUN.  Mostly that's all of no net effect, but it must be slowing
> down each call to n-list at least a little bit.

I have a check if the function exists and don't do autoload, like the
real autoload function does afaik.

-- 
Best regards,
Sebastian Gniazdowski

[-- Attachment #2: aload.zsh3.txt --]
[-- Type: text/plain, Size: 1330 bytes --]

#!/bin/zsh

emulate -LR zsh

--reload-and-run () {
    local fpath_prefix="$1" autoload_opts="$2" func="$3"
    shift 3
    unfunction "$func"
    local FPATH="$fpath_prefix":"${FPATH}"
    builtin autoload $=autoload_opts "$func"
    "$func" "$@"
}

fbody1='#!/bin/zsh
str=""
str=${(r:100000::_:)str};
arr=( "${(@s::)str}" )
repeat 10; do
    aload_fun "${arr[@]}"
done
'

fbody2='#!/bin/zsh
str=""
str=${(r:100000::_:)str};
arr=( "${(@s::)str}" )
repeat 10; do
    arr2=( "${(@M)arr:#(#a1)_}" )
done
'

echo "$fbody1" > aload_fun_main
echo "$fbody2" > aload_fun

# Normal autoload
FPATH+=:`pwd`
autoload aload_fun_main
autoload aload_fun
echo "Normal autoload:"
time ( aload_fun_main )
unfunction aload_fun_main
unfunction aload_fun

# Special autoload
eval "
function aload_fun_main {
    local FPATH=$FPATH:`pwd`
    autoload -X
}
"
eval "
function aload_fun {
    local FPATH=$FPATH:`pwd`
    autoload -X
}
"
echo "Special autoload:"
time ( aload_fun_main )
unfunction aload_fun_main
unfunction aload_fun

# More special autoload
PLUGIN_DIR=`pwd`
eval "
function aload_fun_main {
    --reload-and-run ${(q)PLUGIN_DIR} '' aload_fun_main
}
"
eval "
function aload_fun {
    --reload-and-run ${(q)PLUGIN_DIR} '' aload_fun
}
"
echo "More special autoload:"
time ( aload_fun_main )
unfunction aload_fun_main
unfunction aload_fun


[-- Attachment #3: aload.zsh2.txt --]
[-- Type: text/plain, Size: 1368 bytes --]

#!/bin/zsh

emulate -LR zsh

--reload-and-run () {
    local fpath_prefix="$1" autoload_opts="$2" func="$3"
    shift 3
    unfunction "$func"
    local FPATH="$fpath_prefix":"${FPATH}"
    builtin autoload $=autoload_opts "$func"
    "$func" "$@"
}

fbody1='#!/bin/zsh
str=""
str=${(r:100000::_:)str};
arr=( "${(@s::)str}" )
repeat 10; do
    aload_fun
done

#print -rl "${arr2[@]}"
'

fbody2='#!/bin/zsh
str=""
str=${(r:100000::_:)str};
arr=( "${(@s::)str}" )
repeat 10; do
    arr2=( "${(@M)arr:#(#a1)_}" )
done

#print -rl "${arr2[@]}"
'

echo "$fbody1" > aload_fun_main
echo "$fbody2" > aload_fun

# Normal autoload
FPATH+=:`pwd`
autoload aload_fun_main
autoload aload_fun
echo "Normal autoload:"
time ( aload_fun_main )
unfunction aload_fun_main
unfunction aload_fun

# Special autoload
eval "
function aload_fun_main {
    local FPATH=$FPATH:`pwd`
    autoload -X
}
"
eval "
function aload_fun {
    local FPATH=$FPATH:`pwd`
    autoload -X
}
"
echo "Special autoload:"
time ( aload_fun_main )
unfunction aload_fun_main
unfunction aload_fun

# More special autoload
PLUGIN_DIR=`pwd`
eval "
function aload_fun_main {
    --reload-and-run ${(q)PLUGIN_DIR} '' aload_fun_main
}
"
eval "
function aload_fun {
    --reload-and-run ${(q)PLUGIN_DIR} '' aload_fun
}
"
echo "More special autoload:"
time ( aload_fun_main )
unfunction aload_fun_main
unfunction aload_fun


  reply	other threads:[~2016-06-11  7:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-08  9:34 Sebastian Gniazdowski
2016-05-08 16:35 ` Bart Schaefer
2016-05-16 15:01   ` Sebastian Gniazdowski
2016-05-17 10:18     ` Bart Schaefer
2016-05-18 15:16       ` Sebastian Gniazdowski
2016-06-11  3:30     ` Bart Schaefer
2016-06-11  7:40       ` Sebastian Gniazdowski [this message]
2016-06-11  8:07         ` Sebastian Gniazdowski
2016-06-12 15:39         ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKc7PVDzNgEti5MfzgmaQ6hRHhqiQ-E2na-38tNak3zh_141Lg@mail.gmail.com \
    --to=sgniazdowski@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).