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

Lazy functions like in Vim autoloading, however slower, maybe inspire someone



Hello
A script `ztransform` changes plugin.zsh file:

echo "plugin loaded"
a() { echo "a"; }
b() { echo "b"; }

into:

- file "preamble.zini":
echo "plugin loaded"

- file "functions.zini":
[a^Afun]
 echo "a";
PLG_END_F

[b^Afun]
 echo "b";
PLG_END_F

At load time, preamble.ini is sourced, while function.zini is changed to:

% echo $functions[a]
    functions[a]="${ZPLG_FBODIES[a]}"
    a "$@"

with `ziniload functions.zini` call. Ziniload has most basic parsing with fgets(). So this should:
a) cause no slow down,
b) cause speed up for .plugin.zsh files rich in functions

However I get 104 ms:
 1)   19         104,15     5,48   73,86%     52,76     2,78   37,41%  (anon)

for traditional sourcing, and 125 ms:
 1)   19         125,44     6,60   76,69%     71,50     3,76   43,72%  (anon)

for ziniload-sourcing.

The point is, like Bart said, that parsing might be slow. When I load function body and assign it to ZPLG_FBODIES[fname], I do zero parsing, except of bin_eval ran on:

const char *fun_stubfmt = "%s() { functions[%s]=\"${ZPLG_FBODIES[%s]}\"; %s \"$@\"; };";

Maybe the eval is slow?

I think that winning 50 ms at shell startup is something not to be ignored.

--
Sebastian Gniazdowski
psprint /at/ zdharma.org



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