Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: One more heap optimization trick for zsh < 5.2



On 17 May 2016 at 12:18, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Mon, May 16, 2016 at 8:01 AM, Sebastian Gniazdowski
> <sgniazdowski@xxxxxxxxx> wrote:
>>
>> I was testing the same input with 89k lines. The cause now
>> accidentally clarified. It's about zplugin's shadowing of autoload
>
> Are you sure it's the wrapper and not the autoloading?  It's pretty
> common for the first run of an autoloaded function to be slower than
> subsequent runs.

I tested with zplugin and without it, and slow down occurs in first
case. Also, I wanted to move a normal function outside a file to make
it autoloaded function. It started to be painfully slow when used with
zplugin. Luckily I can optimize for 5.1 and use normal hand-made
"autoload -X" body instead of the wrapper. So zplugin's future is in
general safe.

Tried to construct synthetic test (attached). In general the results
are inconsistent. Their order changes depending even on given run.
Could came up with following alerting times:

# ./aload2.zsh.txt
More special autoload:
( aload_fun; )  3,68s user 0,18s system 98% cpu 3,909 total
Special autoload:
( aload_fun; )  3,08s user 0,18s system 99% cpu 3,277 total
Normal autoload:
( aload_fun; )  3,83s user 0,18s system 99% cpu 4,026 total

# ./aload2.zsh.txt
More special autoload:
( aload_fun; )  2,90s user 0,19s system 99% cpu 3,115 total
Special autoload:
( aload_fun; )  3,24s user 0,18s system 99% cpu 3,436 total
Normal autoload:
( aload_fun; )  3,62s user 0,18s system 99% cpu 3,812 total

# ./aload2.zsh.txt
More special autoload:
( aload_fun; )  2,86s user 0,18s system 99% cpu 3,050 total
Special autoload:
( aload_fun; )  3,22s user 0,18s system 99% cpu 3,402 total
Normal autoload:
( aload_fun; )  3,94s user 0,19s system 99% cpu 4,148 total

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" "$@"
}

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

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

echo "$fbody" > aload_fun
#chmod +x aload_fun

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

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

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



Messages sorted by: Reverse Date, Date, Thread, Author