From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6532 invoked by alias); 5 Jun 2017 05:17:46 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 41226 Received: (qmail 14778 invoked from network); 5 Jun 2017 05:17:46 -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.028167 secs); 05 Jun 2017 05:17:46 -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 (17) Date: Mon, 5 Jun 2017 07:17:36 +0200 From: Sebastian Gniazdowski To: zsh-workers@zsh.org Message-ID: Subject: Lazy functions like in Vim autoloading, however slower, maybe inspire someone X-Mailer: Airmail (231) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello A script =60ztransform=60 changes plugin.zsh file: echo =22plugin loaded=22 a() =7B echo =22a=22; =7D b() =7B echo =22b=22; =7D into: - file =22preamble.zini=22: echo =22plugin loaded=22 - file =22functions.zini=22: =5Ba=5EAfun=5D =C2=A0echo =22a=22; PLG=5FEND=5F=46 =5Bb=5EAfun=5D =C2=A0echo =22b=22; PLG=5FEND=5F=46 At load time, preamble.ini is sourced, while function.zini is changed to:= % echo =24functions=5Ba=5D =C2=A0 =C2=A0 functions=5Ba=5D=3D=22=24=7BZPLG=5F=46BODIES=5Ba=5D=7D=22 =C2=A0 =C2=A0 a =22=24=40=22 with =60ziniload functions.zini=60 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: =C2=A01) =C2=A0 19 =C2=A0 =C2=A0 =C2=A0 =C2=A0 104,15 =C2=A0 =C2=A0 5,48 = =C2=A0 73,86% =C2=A0 =C2=A0 52,76 =C2=A0 =C2=A0 2,78 =C2=A0 37,41% =C2=A0= (anon) for traditional sourcing, and 125 ms: =C2=A01) =C2=A0 19 =C2=A0 =C2=A0 =C2=A0 =C2=A0 125,44 =C2=A0 =C2=A0 6,60 = =C2=A0 76,69% =C2=A0 =C2=A0 71,50 =C2=A0 =C2=A0 3,76 =C2=A0 43,72% =C2=A0= (anon) for ziniload-sourcing. The point is, like Bart said, that parsing might be slow. When I load fun= ction body and assign it to ZPLG=5F=46BODIES=5Bfname=5D, I do zero parsin= g, except of bin=5Feval ran on: const char *fun=5Fstubfmt =3D =22%s() =7B functions=5B%s=5D=3D=5C=22=24=7B= ZPLG=5F=46BODIES=5B%s=5D=7D=5C=22; %s =5C=22=24=40=5C=22; =7D;=22; Maybe the eval is slow=3F I think that winning 50 ms at shell startup is something not to be ignore= d. -- Sebastian Gniazdowski psprint /at/ zdharma.org