From: Sebastian Gniazdowski <psprint@zdharma.org>
To: zsh-workers@zsh.org
Subject: Lazy functions like in Vim autoloading, however slower, maybe inspire someone
Date: Mon, 5 Jun 2017 07:17:36 +0200 [thread overview]
Message-ID: <etPan.5934e970.6b8b4567.cca3@MacMini.local> (raw)
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
next reply other threads:[~2017-06-05 5:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-05 5:17 Sebastian Gniazdowski [this message]
2017-06-05 12:23 ` Sebastian Gniazdowski
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=etPan.5934e970.6b8b4567.cca3@MacMini.local \
--to=psprint@zdharma.org \
--cc=zsh-workers@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).