From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25206 invoked by alias); 14 Feb 2016 14:41:23 -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: 37967 Received: (qmail 22099 invoked from network); 14 Feb 2016 14:41:23 -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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 Date: Sun, 14 Feb 2016 14:34:41 +0000 From: Daniel Shahaf To: Sebastian Gniazdowski Cc: Zsh hackers list Subject: Re: Slow highlighting (Re: "drop-in replacement" and transpose-words-match) Message-ID: <20160214143441.GB11737@tarsus.local2> References: <160118223126.ZM28565@torch.brasslantern.com> <160119195608.ZM31931@torch.brasslantern.com> <20160123235303.GE20278@tarsus.local2> <160123222057.ZM16192@torch.brasslantern.com> <160210101846.ZM2333@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sebastian Gniazdowski wrote on Thu, Feb 11, 2016 at 17:11:57 +0100: > On 11 February 2016 at 11:43, Sebastian Gniazdowski > wrote: > > That said, zsyh could be somewhat optimized if the ":howmany" syntax > > would be utilized. > > Could came up with this: > ./parse.zsh "zplugin.zsh" > out1.txt 128,78s user 8,61s system 99% cpu > 2:17,85 total > ./parse.zsh "zplugin.zsh" > out2.txt 74,34s user 8,38s system 99% cpu > 1:23,12 total > > https://github.com/zsh-users/zsh-syntax-highlighting/pull/272 > Thanks! Merged, will be in 0.5.0. However, I think avoiding the strlen() isn't the main benefit here: I suspect the expression $buf[start_pos+1,-1], which is evaluated in every iteration of the loop, might have triggered an O(N²) allocations pattern, even before considering the implicit strlen for the -1 (or the explicit strlen in the "else" branch). The next step might be to see whether the two remaining instances of that expression (one in the 'if' branch and one in the 'else' branch) can also be simplified: for example, by precomputing the indices of all newlines, semicolons, and starts-of-words (places where the regexp /\