From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 3e7cca5f for ; Fri, 6 Sep 2019 14:11:22 +0000 (UTC) Received: (qmail 18964 invoked by alias); 6 Sep 2019 14:11: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: List-Unsubscribe: X-Seq: 24217 Received: (qmail 1172 invoked by uid 1010); 6 Sep 2019 14:11:13 -0000 X-Qmail-Scanner-Diagnostics: from mail-io1-f54.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.2/25559. spamassassin: 3.4.2. Clear:RC:0(209.85.166.54):SA:0(-2.0/5.0):. Processed in 1.335869 secs); 06 Sep 2019 14:11:13 -0000 X-Envelope-From: roman.perepelitsa@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.166.54 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=/PcXF21p16FArzYURz9cIfl0Ki0UlYNswm8AJvZZAso=; b=Rpw4md24eyqcxYSMybR2ftgRLNlXfNlNdcnM9Zs8sGehDU/1K20E0KQSSvGV6dGoPV ux70Y5uzSfa+5NTiMRrHnApxxRfioGWENuee/UM0t/mazisznjqtFBJxwD3eeo6vptoe QHhSpIs3Bl/4Dei3WlktDNE6iVBSpPD0tXNG2CbR9JSHnfrnur08YQxsUuiHMegYef+Z ucYZpSKIJyD7diVKu5pSnK9rbCebGgCsAuuBpybDtg3OEdRGTrjj9XbxOGHO2374DgEg fm1v5xZqIA39Yqq1j4SBinn8JIYhi2QVSS51g8/zfH9LOG9NBukrCPEBivTsAZlutq9T 1o+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=/PcXF21p16FArzYURz9cIfl0Ki0UlYNswm8AJvZZAso=; b=Rq2hIGfU7xEDz8mJwzXqeNb39o0jqVWiwwXG2nUIu1oY4TFGaKNmYAvs/Yk2qKuPXb n2ZSyBApmzoY4H1uy+ZHuU3q5a/Oz+x7lscwXV8n3rj+yWl7m62vlQ/X7wjLr769E4fi JmPgRlub+ETaqt1d5B3qSLBS9FdmLVVpDwXoYmWyQrMSfYzT49Wz08K8Sab+wiQfqbxT hgH2OrdxsuT4Y4zjTZ723AMhsOi9QDre7/meWNzzcnaCebvqfMK4ic+LEkqC0b68SDb0 z7VxCPprjt5S2Tcxr+XsFtbx1S3vE8xPae6BbtZHFwYexPQsKQ2KC351XgXJH8bM0nPt iT2g== X-Gm-Message-State: APjAAAWP6AXb6u3QxboqJfLPVhKcaw6CaRXPWZFtFHjfU+i9QpJxAw1y EwSSCFoMwH37+HyxcteZQFf27lRqxoFyL3oa0oV2E+YSM3M= X-Google-Smtp-Source: APXvYqzoZJXYzmuVBumsYVWOWdD4i+B8Ks309wKpPEOK09O15cJjZB7mieRJE1WwfxY7i1cYyZ+SdMfw+jbPD3Fefw4= X-Received: by 2002:a6b:6303:: with SMTP id p3mr4270862iog.169.1567779039429; Fri, 06 Sep 2019 07:10:39 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Roman Perepelitsa Date: Fri, 6 Sep 2019 16:10:31 +0200 Message-ID: Subject: Re: slow startup of zsh (1x slower than bash) To: Peng Yu Cc: Sebastian Gniazdowski , julien.nicoulaud@gmail.com, zsh-users Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Sep 6, 2019 at 3:44 PM Peng Yu wrote: > I build a library that one causes another. In such cases, the > startup time matters, as most of scripts don=E2=80=99t take a long > time to run, I don=E2=80=99t want the startup eat up too much time. > I know I can use =E2=80=98source=E2=80=99 circumvent this problem to a ce= rtain extent. Autoloading was designed to solve this problem (among others). Give it a try. Your zsh scripts might become orders of magnitude faster than in bash and you don't even have to change them. For example, suppose you have two files in your ~/bin: % cat ~/bin/greet #!/usr/bin/env zsh print -r "Hello, $1" % cat ~/bin/spam #!/usr/bin/env zsh repeat $1 greet $2 Let's further suppose that ~/bin is in your $PATH. % spam 3 $USER Hello, romka Hello, romka Hello, romka You can make greet and spam much faster by adding these two lines to your ~/.zshrc: fpath+=3D~/bin autoload -Uz ~/bin/*(x:t) On my system this simple 2-line addition to ~/.zshrc speeds up `spam 3 $USER` by a factor of 5000. Note that you can still invoke your scripts the same way as before. Use ~/bin/spam or =3Dspam to force-spawn a new shell process, while the plain spam will call a function within the same shell process. The first call to spam will automatically source ~/bin/spam and turn it into a function. > But having a shorter startup time is still a good thing. If bash can > do it, I don=E2=80=99t think zsh is absolutely unable to do it. Faster is always better than slower but when there is no practical difference then the development effort might be better spent elsewhere. Everyone's environment is different but from my point of view zsh startup is fast enough to be indistinguishable from zero. Roman.