From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 22158 invoked from network); 30 Nov 2021 02:31:07 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 30 Nov 2021 02:31:07 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1638239467; b=R8wKuQBD2uH4q7uoxeaQOd5El4F3oxSRxUWepwlsUbCIsjTCoq8w59umO58y4tCCXDOMRffchl /ju9F1+agUhqBmiUtf35nMzed4+0IX3cCosqMSaqr3Nk6pODEeeM6ZIyDI+L4MtTeWUPoES21L 9Ecwx85MedshXFK9RtNzhriLn2o77Rcz3z6Ni8xaS1VagpDt5q+XXpa4trC/yHc+GoYLNelyXO +rXwMXFky4vETL65VsnFlCDQ4W6Im04wb6hM+NS1yZY51E2rKRdmqFv28gtHygYqNB7Va5LT+O 5TOPSjtVwJjXllAOD4df5ABET/Tbzfm2rGqJgxFUmBMYYw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-wm1-f50.google.com) smtp.remote-ip=209.85.128.50; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1638239467; bh=4pyubYzpS/pKwsd/JWscd/Z53w747iLntU0ZEgdpcT4=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=O7szzr0Hl+NWCjfxuZkRVV3cvR5H+SfYxgYGuDJKu22fk4zuc91258Qap9ShvMTVZJy8UO/YAJ 3EKhFFaZWBemfzfdWqp2+5WOrIgfP61KKn4obQXQZkhLbqDSN3DJqr5FfdMw0LoXSCpVoC/VrV fXvCFUA3yg5FM9Ad9zLqh3QFjOz7jIlCpmEYAwMHx7EwBU9meVBB2EeV0oCkFjdvKUu6hLmUj/ zyJeoIHX2pwdk3cJ7RjS1lDClvvM6HvPPTmy4hzo4pD2v68s5wLmRcIIwlCrawLHF5A+CgScxG Oq5DnVm4T8PHm6/9ixGmRjP2P/rdhUsCB7MMX+4Bf7Ka1w==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=RoMJmvNzbhLWliZ1Gc2BzkIrMqJnXhw1MTsS8536UOE=; b=l2DSCAZoYUY1St1W45HlWppY6n lp+xJMPX8clslqCKrCmobfTz0RtEAPWE4uzGXyulpKutSLPW1mvc4ZIVn7QcwmNrrDF2dIYnU8rH4 V2WzbGbHIlViDDKlNuOdV8oTtb7NsGZ0ywEFK4h/RcoZcowJXTTxfs0myVjWTX7RlObml4SJNJtbO 2rm+uP3Sz/T9NsH3h1QQtWnA0EJ4ara3FIUL2sSGXD/YYZuSmwqnevPTTGiuewef1URvCHQz1WpQ2 4PFPY8zYdqlXBz2C9BdGJ7KRDAxlJlFGu/Lgv/5amGGQD9PiMyzHnVkx/o8tzoYcBoUuVTfCuyXcY Psmf9o6Q==; Received: from authenticated user by zero.zsh.org with local id 1mrsvD-000O8e-6J; Tue, 30 Nov 2021 02:31:07 +0000 Authentication-Results: zsh.org; iprev=pass (mail-wm1-f50.google.com) smtp.remote-ip=209.85.128.50; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-wm1-f50.google.com ([209.85.128.50]:36718) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1mrsuW-000NS5-GX; Tue, 30 Nov 2021 02:30:24 +0000 Received: by mail-wm1-f50.google.com with SMTP id i8-20020a7bc948000000b0030db7b70b6bso18320593wml.1 for ; Mon, 29 Nov 2021 18:30:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RoMJmvNzbhLWliZ1Gc2BzkIrMqJnXhw1MTsS8536UOE=; b=F3/tNnNcv6uFMc2PeN48v5agFrAD+obHJJV/pQEII3+y/jcdt/RcpbsnPgGdVTkZVn Z1MkpJyZkvX4tEO+u1pAVLrDMHraAAfaLXjZZTPNTtkeQ7EasFN49UjBkIy53WdGzT/x NH77FVM5wvLDztuX8c2i7cIRazVjja4yKxK92XbRKy5pCuGoWrr2VhSBHr/7deWGn1Xo a3swXOc3eYuD1wh92MY0GEjqF3ysWfD8ge8656DtTSAa8FgrpfWiBSrAZGTl+C5+rAPM 8DmCyxh0cE9WC3EcYZfAHwvgSYfSXyNjulyAs7spyAK0uAgHQYnsJM0rSvAQJJCz+rRe BMrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RoMJmvNzbhLWliZ1Gc2BzkIrMqJnXhw1MTsS8536UOE=; b=Zc6wtuQGub2f8Qd42k+ZkI2+ZEzQLmxaja9TqAqcSVjD/WRp8h6vPOTlaQdGgZgvk/ AU9Sarr5jn1myV7SGdijY0TpGWotYxE5n1m4/J5PeHBEk4rgh5axkN3EdUucPGSPMCIc jH7mX2qPanmoY7B3UxuFFHG1ZT6wlwIThgpyFQwDlS4AVwWq7Rqt1DZWX/Pc6LB42VD2 ZD/HhYgtRhUoUFwju8RAbmsvKlzxAeQ0UsGBI8lHjEReRQefTNZi67NDFEyYggOVAbob 2ksqTjZLrV5QKl22qGT+heUPk+F7PCEpmlD1ay4MoHZb9EPRgS7NsZwOZ0tDm3tzTkW+ nrFg== X-Gm-Message-State: AOAM530v/bQMkfaLhH0/wtOIdTxMZnt72BNZw87ZdEYmWNrfL9jsafFn VIsUoCBQ9laE8nraE9PZ6DWzh7aGTi/0w4IGUnPyC+zOb+NA0g== X-Google-Smtp-Source: ABdhPJywuParlZzXXGpGoPAn39ns5igIB6bDKUcifTSzVXbmdNbK4A22T6y4B/iuue0BXDkeoh9stqWAAvEcIHwXkwI= X-Received: by 2002:a7b:ca4c:: with SMTP id m12mr1890889wml.119.1638239423884; Mon, 29 Nov 2021 18:30:23 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Zach Riggle Date: Mon, 29 Nov 2021 20:30:12 -0600 Message-ID: Subject: Re: Shell startup, aliases vs. functions vs. autoloadable functions, and zcompile benefits To: Bart Schaefer Cc: Zsh Users Content-Type: multipart/alternative; boundary="000000000000eaf4a005d1f85616" X-Seq: 27392 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: --000000000000eaf4a005d1f85616 Content-Type: text/plain; charset="UTF-8" Good points all around! I did play around with hyperfine compiling all zsh scripts in ~/.zprezto and didn't see a tangible difference. The benchmark I used $ hyperfine 'zsh -i -l "exit 0"' Obviously this is not the BEST benchmark, but it is useful for checking shell startup time -- I might give zsh-bench a look. I did spend a lot of time with zprof to benchmark my init scripts, but the most time-consuming is simply the "source" statement loading other things, but there's no context as to WHICH files being sourced take the most time. > you might end up with a mismatched zwc with greater mtime. This is something I expected to cause hard-to-diagnose problems. Luckily, the most common way I'd change files inadvertently (git checkout branchname) does not use the time from the commit. I would expect that the md5sum of a file is reasonably fast, and could be stored in the .zwc for sanity checking, instead of just the "newer than" check. > Again you're unlikely to notice unless your $fpath entries are numerous and deep > The tradeoff is that the third one occupies less memory than either of the other two (though about the same as the alias) which is significant if there are a lot of seldom-used functions. I expect that I have more $fpath entries than usual, but the total number of autoloadable functions is much more. $ echo $#fpath 22 $ for d in $fpath; do n=$(ls $d/* | wc -l); echo "$n $d"; done | sort -nr | head -3 1162 /usr/share/zsh/5.8/functions 559 /usr/share/zsh/site-functions 141 /Users/zachriggle/.zprezto/modules/completion/external/src *Zach Riggle* On Sat, Nov 27, 2021 at 2:22 PM Bart Schaefer wrote: > On Sat, Nov 27, 2021 at 12:33 AM Roman Perepelitsa > wrote: > > > > On Sat, Nov 27, 2021 at 9:11 AM Zach Riggle > wrote: > > > > > > alias foo='foo --flag1 --flag2' > > > foo() { command foo --flag1 --flag2 "$@" } > > > autoloadable module containing (2) > > > > In theory the first and the last should have the same performance and > > the middle should be slower because it has to parse the body. In > > practice you won't find any difference: zsh parser is very fast. > > This is true for shell startup time; at runtime there's a small > penalty for the middle one (allocating the function context) and on > the very first execution there's an additional load-time cost for the > third one. Again you're unlikely to notice unless your $fpath entries > are numerous and deep. > > The tradeoff is that the third one occupies less memory than either of > the other two (though about the same as the alias) which is > significant if there are a lot of seldom-used functions. > > Otherwise, everything Roman said. > --000000000000eaf4a005d1f85616 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Good points all around!=C2=A0 I did play around with hyper= fine compiling all zsh scripts in ~/.zprezto=C2=A0and didn't see a tang= ible difference.

The benchmark I used=C2=A0

=
=
$ hyperfine 'zsh -i -l "exit 0"'
<= div>
Obviously this is not the BEST benchmark, but it is usef= ul for checking shell startup time -- I might give zsh-bench a look.=C2=A0 = I did spend a lot of time with zprof to benchmark my init scripts, but the = most time-consuming is simply the "source" statement loading othe= r things, but there's no context as to WHICH files being sourced take t= he most time.

> you might end up with a mismatched z= wc with greater mtime.
This is = something I expected to cause hard-to-diagnose problems.=C2=A0 Luckily, the= most common way I'd change files inadvertently (git checkout branchnam= e) does not use the time from the commit.

I would expect that the md5sum of a file is reasonably f= ast, and could be stored in the .zwc for sanity checking, instead of just t= he "newer than" check.

>=C2=A0Again you're unlikely to notice unless your = $fpath entries are numerous and deep

> The trad= eoff is that the third one occupies less memory than either of the other tw= o (though about the same as the alias) which is significant if there are a = lot of seldom-used functions.

I expect that I have= more $fpath entries than usual, but the total number of autoloadable funct= ions is much more.

$ echo $#fpath
=
22

$ for d in $fpat= h; do n=3D$(ls $d/* | wc -l); echo "$n $d"; done | sort -nr | hea= d -3
=C2=A0 =C2=A0 1162 /usr/share/zsh/5.8/functions
=C2=A0 =C2=A0 = =C2=A0559 /usr/share/zsh/site-functions
=C2=A0 =C2=A0 =C2=A0141 /Users/z= achriggle/.zprezto/modules/completion/external/src
<= /blockquote>
<= div dir=3D"ltr">
Zach Rig= gle



On Sat, Nov 27, 2021 at= 2:22 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
On Sat, Nov 27, 2021 at 12:33 AM Ro= man Perepelitsa
<roman.= perepelitsa@gmail.com> wrote:
>
> On Sat, Nov 27, 2021 at 9:11 AM Zach Riggle <zachriggle@gmail.com> wrote:
> >
> > alias foo=3D'foo --flag1 --flag2'
> > foo() { command foo --flag1 --flag2 "$@" }
> > autoloadable module containing (2)
>
> In theory the first and the last should have the same performance and<= br> > the middle should be slower because it has to parse the body. In
> practice you won't find any difference: zsh parser is very fast.
This is true for shell startup time; at runtime there's a small
penalty for the middle one (allocating the function context) and on
the very first execution there's an additional load-time cost for the third one.=C2=A0 Again you're unlikely to notice unless your $fpath ent= ries
are numerous and deep.

The tradeoff is that the third one occupies less memory than either of
the other two (though about the same as the alias) which is
significant if there are a lot of seldom-used functions.

Otherwise, everything Roman said.
--000000000000eaf4a005d1f85616--