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,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 8538 invoked from network); 27 Sep 2021 18:17:03 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 27 Sep 2021 18:17:03 -0000 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:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:From:Reply-To:Cc: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=G5HpzqlHuhC00zUbPQ/XToDvB/cY7cms0XfuX9RUf/g=; b=GaIM8uuhqI9qPb/cTpxzyZXOXM Mc1/KA6eM+sfYQ0G4NuCP1eAx17Y0Ii+Rd7dqk1tosHj2MV0n4ybxAklFQyX2BfZxMYkFBiGR1kF/ rNPBJjmf1axMngfXbGNkcSaVHtFZ+9ZuyUVIUkZe0/sNY0Z7ttx1lqtgMEifOVBMMIlCGDoNoiLJY EB3RYIsd+OpG5DKc7zOSGTb9jX16bQLK9Sl5fr3pXwBwPex5+dXw6PML8oIOFBI0qOtCZUwPNXO+J gCK/dQH+U6wPbjF/qv9Lda98TUsGtwdvMTiWHPEwwprP7HrYs6VF+mY1aM5WUUuUYcNE1MJU6WFqY 3banJ9Vw==; Received: from authenticated user by zero.zsh.org with local id 1mUvBV-000F91-Sz; Mon, 27 Sep 2021 18:17:02 +0000 Received: from authenticated user by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1mUvAw-000ErD-Pf; Mon, 27 Sep 2021 18:16:27 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.94.2) (envelope-from ) id 1mUvAv-000Cmq-6a for zsh-workers@zsh.org; Mon, 27 Sep 2021 20:16:25 +0200 From: Oliver Kiddle To: Zsh workers Subject: PATCH: don't reopen completion dump for append 26 times MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <49154.1632766585.1@hydra> Date: Mon, 27 Sep 2021 20:16:25 +0200 Message-ID: <49155-1632766585.200905@F_BP.pomt.vBre> X-Seq: 49454 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: I'm getting slow zsh startup times which zprof puts down to zcompdump. The real problem has to be something in my NFS setup which is a separate problem. But changing compdump to not reopen the dump file 26 times for APPEND does alleviate the problem. This appending isn't necessary and avoiding it may help performance in other cases. Most people complaining about slow startup on stackoverflow etc are probably running compinit more than once with a different fpath thanks to their plugin framework so this won't do much for them. However, any objections to the following change? Or would it be better to enclose everything in braces and use a stdout redirection? Oliver diff --git a/Completion/compdump b/Completion/compdump index e0dc8b805..6daf92f9f 100644 --- a/Completion/compdump +++ b/Completion/compdump @@ -16,7 +16,7 @@ emulate -L zsh setopt extendedglob noshglob -typeset _d_file _d_f _d_bks _d_line _d_als _d_files _d_name _d_tmp +typeset _d_file _d_f _d_fd _d_bks _d_line _d_als _d_files _d_name _d_tmp _d_file=${_comp_dumpfile-${0:h}/compinit.dump}.$HOST.$$ [[ $_d_file = //* ]] && _d_file=${_d_file[2,-1]} @@ -33,44 +33,45 @@ if [[ -n "$_comp_secure" ]]; then (( $#_d_wdirs )) && _d_files=( "${(@)_d_files:#(${(j:|:)_d_wdirs})/*}" ) fi -print "#files: $#_d_files\tversion: $ZSH_VERSION" > $_d_file +exec {_d_fd}>$_d_file +print "#files: $#_d_files\tversion: $ZSH_VERSION" >& $_d_fd # Dump the arrays _comps, _services and _patcomps. The quoting # hieroglyphics ensure that a single quote inside a variable is itself # correctly quoted. -print "\n_comps=(" >> $_d_file +print "\n_comps=(" >& $_d_fd for _d_f in ${(ok)_comps}; do print -r - "${(qq)_d_f}" "${(qq)_comps[$_d_f]}" -done >> $_d_file -print ")" >> $_d_file +done >& $_d_fd +print ")" >& $_d_fd -print "\n_services=(" >> $_d_file +print "\n_services=(" >& $_d_fd for _d_f in ${(ok)_services}; do print -r - "${(qq)_d_f}" "${(qq)_services[$_d_f]}" -done >> $_d_file -print ")" >> $_d_file +done >& $_d_fd +print ")" >& $_d_fd -print "\n_patcomps=(" >> $_d_file +print "\n_patcomps=(" >& $_d_fd for _d_f in ${(ok)_patcomps}; do print -r - "${(qq)_d_f}" "${(qq)_patcomps[$_d_f]}" -done >> $_d_file -print ")" >> $_d_file +done >& $_d_fd +print ")" >& $_d_fd _d_tmp="_postpatcomps" -print "\n_postpatcomps=(" >> $_d_file +print "\n_postpatcomps=(" >& $_d_fd for _d_f in ${(ok)_postpatcomps}; do print -r - "${(qq)_d_f}" "${(qq)_postpatcomps[$_d_f]}" -done >> $_d_file -print ")" >> $_d_file +done >& $_d_fd +print ")" >& $_d_fd -print "\n_compautos=(" >> $_d_file +print "\n_compautos=(" >& $_d_fd for _d_f in "${(ok@)_compautos}"; do print -r - "${(qq)_d_f}" "${(qq)_compautos[$_d_f]}" -done >> $_d_file -print ")" >> $_d_file +done >& $_d_fd +print ")" >& $_d_fd -print >> $_d_file +print >& $_d_fd # Now dump the key bindings. We dump all bindings for zle widgets # whose names start with a underscore. @@ -90,15 +91,15 @@ zle -lL | print -r - ${_d_line} _d_bks+=(${_d_line[3]}) fi - done >> $_d_file + done >& $_d_fd bindkey | while read -rA _d_line; do if [[ ${_d_line[2]} = (${(j.|.)~_d_bks}) ]]; then print -r "bindkey '${_d_line[1][2,-2]}' ${_d_line[2]}" fi - done >> $_d_file + done >& $_d_fd -print >> $_d_file +print >& $_d_fd # Autoloads: look for all defined functions beginning with `_' (that also @@ -109,7 +110,7 @@ _d_als=($^fpath/(${(o~j.|.)$(typeset +fm '_*')})(N:t)) # print them out: about five to a line looks neat integer _i=5 -print -n autoload -Uz >> $_d_file +print -n autoload -Uz >& $_d_fd while (( $#_d_als )); do if (( ! $+_compautos[$_d_als[1]] )); then print -n " $_d_als[1]" @@ -119,19 +120,20 @@ while (( $#_d_als )); do fi fi shift _d_als -done >> $_d_file +done >& $_d_fd -print >> $_d_file +print >& $_d_fd local _c for _c in "${(ok@)_compautos}"; do - print "autoload -Uz $_compautos[$_c] $_c" >> $_d_file + print "autoload -Uz $_compautos[$_c] $_c" >& $_d_fd done -print >> $_d_file +print >& $_d_fd -print "typeset -gUa _comp_assocs" >> $_d_file -print "_comp_assocs=( ${(qq)_comp_assocs} )" >> $_d_file +print "typeset -gUa _comp_assocs" >& $_d_fd +print "_comp_assocs=( ${(qq)_comp_assocs} )" >& $_d_fd +exec {_d_fd}>&- mv -f $_d_file ${_d_file%.$HOST.$$}