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: Wed, 18 May 2016 17:16:23 +0200	[thread overview]
Message-ID: <CAKc7PVCy0gaVBcWiCdSHvNA9iGmML88aFAh7FL0MiHMqNa-YNA@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7Z3YUUpNQ+rNAT_FRhecqDVA4Z-oTzbT6KJeeA8SccELQ@mail.gmail.com>

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

On 17 May 2016 at 12:18, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Mon, May 16, 2016 at 8:01 AM, Sebastian Gniazdowski
> <sgniazdowski@gmail.com> 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

[-- Attachment #2: aload2.zsh.txt --]
[-- Type: text/plain, Size: 927 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" "$@"
}

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


  reply	other threads:[~2016-05-18 15:16 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 [this message]
2016-06-11  3:30     ` Bart Schaefer
2016-06-11  7:40       ` Sebastian Gniazdowski
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=CAKc7PVCy0gaVBcWiCdSHvNA9iGmML88aFAh7FL0MiHMqNa-YNA@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).