Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Why sourcing a file is not faster than doing a loop with eval, zle -N
- X-seq: zsh-users 22729
- From: Sebastian Gniazdowski <psprint@xxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Why sourcing a file is not faster than doing a loop with eval, zle -N
- Date: Sat, 17 Jun 2017 13:34:00 +0200
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
Hello,
I've tried to optimize my fast-syntax-highlighting. The idea is simple, instead of a loop:
for cur_widget in $widgets_to_bind; do
case $widgets[$cur_widget] in
...
builtin) eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _call_widget .${(q)cur_widget} -- \"\$@\" }"
zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;;
...
...
I do, in the same loop:
...
print -r "zle -N" "$prefix-$cur_widget" "${widgets[$cur_widget]#*:}" >>| ~/.fsh_cache
...
and so on, to then only detect ~/.fsh_cache, and source it, skipping the loop. Times of "zsh -i -c exit" are:
- normal FSH: 0.3968 sec on average
- cache-feature FSH: 0.4329 sec on average
- zcompiled cache: 0.3831 sec on average
So, only after compiling ~/.fsh_cache, I get slightly better time, normally it is ~30 ms slower. I would expect this to be always and more faster. Why it is not?
I now suspect that maybe there's more parsing – loop doesn't have 554 lines like ~/.fsh_cache, and is parsed quickier.
Test data: https://github.com/zdharma/hacking-private/tree/master/FSH
--
Sebastian Gniazdowski
psprint /at/ zdharma.org
Messages sorted by:
Reverse Date,
Date,
Thread,
Author