From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26667 invoked by alias); 17 Jun 2017 11:34:13 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 22729 Received: (qmail 20534 invoked from network); 17 Jun 2017 11:34:13 -0000 X-Qmail-Scanner-Diagnostics: from aok120.rev.netart.pl by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(85.128.245.120):SA:0(0.0/5.0):. Processed in 2.111278 secs); 17 Jun 2017 11:34:13 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: psprint@zdharma.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at zdharma.org does not designate permitted sender hosts) X-Virus-Scanned: by amavisd-new using ClamAV (21) Date: Sat, 17 Jun 2017 13:34:00 +0200 From: Sebastian Gniazdowski To: zsh-users@zsh.org Message-ID: Subject: Why sourcing a file is not faster than doing a loop with eval, zle -N X-Mailer: Airmail (442) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello, I've tried to optimize my fast-syntax-highlighting. The idea is simple, i= nstead of a loop: =C2=A0 for cur=5Fwidget in =24widgets=5Fto=5Fbind; do =C2=A0 =C2=A0 case =24widgets=5B=24cur=5Fwidget=5D in =C2=A0 =C2=A0 =C2=A0 =C2=A0 ... =C2=A0 =C2=A0 =C2=A0 =C2=A0 builtin) eval =22=5Fzsh=5Fhighlight=5Fwidget=5F= =24=7B(q)prefix=7D-=24=7B(q)cur=5Fwidget=7D() =7B =5Fcall=5Fwidget .=24=7B= (q)cur=5Fwidget=7D -- =5C=22=5C=24=40=5C=22 =7D=22 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0zle -N =24cur=5Fwi= dget =5Fzsh=5Fhighlight=5Fwidget=5F=24prefix-=24cur=5Fwidget;; =C2=A0 ... =C2=A0 ... I do, in the same loop: =C2=A0 =C2=A0 ... =C2=A0 =C2=A0 print -r =22zle -N=22 =22=24prefix-=24cur=5Fwidget=22 =22=24= =7Bwidgets=5B=24cur=5Fwidget=5D=23*:=7D=22 >>=7C =7E/.fsh=5Fcache =C2=A0 =C2=A0 ... and so on, to then only detect =7E/.fsh=5Fcache, and source it, skipping = the loop. Times of =22zsh -i -c exit=22 are: - normal =46SH: =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00.3968 sec on average - cache-feature =46SH: =C2=A0 0.4329 sec on average - zcompiled cache: =C2=A0 =C2=A0 0.3831 sec on average So, only after compiling =7E/.fsh=5Fcache, I get slightly better time, no= rmally it is =7E30 ms slower. I would expect this to be always and more f= aster. Why it is not=3F I now suspect that maybe there's more parsing =E2=80=93 loop doesn't have= 554 lines like =7E/.fsh=5Fcache, and is parsed quickier. Test data:=C2=A0https://github.com/zdharma/hacking-private/tree/master/=46= SH --=C2=A0 Sebastian Gniazdowski psprint /at/ zdharma.org