Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: One more heap optimization trick for zsh < 5.2
- X-seq: zsh-users 21647
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: One more heap optimization trick for zsh < 5.2
- Date: Sat, 11 Jun 2016 09:40:46 +0200
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=7Fh0vzNPaPnvbK+/aj4JDVgTmQHwAeiJKyVw9BMVDBY=; b=wX8sITBp+tLzxf2TIC2A7JbLabUwOvkuyCf5+h8jnQ/c11g5O4Twrf02B7zu9myoAV FYC+oAQvnOoNLPfaSJskKwDS1rNaIod8mshVphP7tr6LB36T9RlT/iCAMLQiEmG2q/AP Wz26XVhOJaHdF368fRhFo5tMUOZTAvOxgyRdh6GeaE3VEoBpaaXR2UBO9BcfXsLACoxa qnCe8R9/CFGT+b6p47zZD/jmvDRL8bzmg6gqWZBCH/i34QnBdPwJgGL9Bx+hxlfee1zu ClYS9xsTWqLETHMZV7YJGT9B4x6WotnyDROjxbs3E7GrcGGYV3VRZv2w6wBBp4u0YE7M ueeQ==
- In-reply-to: <160610203056.ZM10515@torch.brasslantern.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVDRk2hx9i0T62fnD=v__1RbB9sPr5ni_mHXLojVa4sotA@mail.gmail.com> <160508093530.ZM9686@torch.brasslantern.com> <CAKc7PVDaLHs3xEVJGFn1F2M0BEEOzZFt8enMis7tTmbVKLx12Q@mail.gmail.com> <160610203056.ZM10515@torch.brasslantern.com>
On 11 June 2016 at 05:30, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> 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
#!/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
#!/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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author