zsh-users
 help / color / mirror / code / Atom feed
* Why sourcing a file is not faster than doing a loop with eval, zle -N
@ 2017-06-17 11:34 Sebastian Gniazdowski
       [not found] ` <CAH+w=7bVXtubcdwvEBC9isE32683dUipAUS=vrAkgO5pp2bkkw@mail.gmail.com>
  0 siblings, 1 reply; 10+ messages in thread
From: Sebastian Gniazdowski @ 2017-06-17 11:34 UTC (permalink / raw)
  To: zsh-users

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


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

end of thread, other threads:[~2017-06-19 19:13 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <etPan.594513a8.516100cd.10b2e__10513.1716504276$1497699329$gmane$org@zdharma.org>
2017-06-19 12:24 ` Why sourcing a file is not faster than doing a loop with eval, zle -N Stephane Chazelas
2017-06-19 15:31   ` Bart Schaefer
     [not found]   ` <170619083116.ZM17323__41722.0601499595$1497886320$gmane$org@torch.brasslantern.com>
2017-06-19 16:16     ` Stephane Chazelas
2017-06-19 19:14       ` Bart Schaefer
2017-06-17 11:34 Sebastian Gniazdowski
     [not found] ` <CAH+w=7bVXtubcdwvEBC9isE32683dUipAUS=vrAkgO5pp2bkkw@mail.gmail.com>
     [not found]   ` <CAH+w=7afTi=1bfLBCmq8-vB-rLWDtEkAtk8gCCna3-mQwZ1-Ow@mail.gmail.com>
2017-06-17 14:05     ` Bart Schaefer
     [not found]     ` <etPan.594538f9.2ea629d6.10b2e@AirmailxGenerated.am>
2017-06-17 14:56       ` Sebastian Gniazdowski
2017-06-17 15:44         ` Sebastian Gniazdowski
2017-06-17 16:39           ` Bart Schaefer
2017-06-17 17:25             ` 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).