zsh-workers
 help / color / mirror / code / Atom feed
* Lazy functions like in Vim autoloading, however slower, maybe inspire someone
@ 2017-06-05  5:17 Sebastian Gniazdowski
  2017-06-05 12:23 ` Sebastian Gniazdowski
  0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Gniazdowski @ 2017-06-05  5:17 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Lazy functions like in Vim autoloading, however slower, maybe inspire someone
  2017-06-05  5:17 Lazy functions like in Vim autoloading, however slower, maybe inspire someone Sebastian Gniazdowski
@ 2017-06-05 12:23 ` Sebastian Gniazdowski
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Gniazdowski @ 2017-06-05 12:23 UTC (permalink / raw)
  To: zsh-workers

On 5 czerwca 2017 at 07:18:09, Sebastian Gniazdowski (psprint@zdharma.org) wrote:
> 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.

It turned out that loading function bodies from `functions.zini` is indeed super fast: 1.39 ms. However, plugin.zsh often calls its defined functions. So the delayed parsing is then triggered, at Zsh startup, and is slower than normal parsing.

So no way out, unless the side-track for functions can be something different, yet being a side-track.
-- 
Sebastian Gniazdowski
psprint /at/ zdharma.org


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-06-05 12:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-05  5:17 Lazy functions like in Vim autoloading, however slower, maybe inspire someone Sebastian Gniazdowski
2017-06-05 12:23 ` Sebastian Gniazdowski

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).