From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#46859: 28.0.50; [PATCH]: Add option to truncate long lines in xref.el Date: Wed, 3 Mar 2021 00:37:08 +0200 Message-ID: <25782781-4baa-5d44-99a1-2e57552ab3a0@yandex.ru> References: <87im69uzlt.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28110"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 To: Theodor Thornhill , juri@linkov.net, 46859@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Mar 02 23:38:10 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lHDec-0007Dk-2U for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 02 Mar 2021 23:38:10 +0100 Original-Received: from localhost ([::1]:45376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lHDeb-0007gw-3o for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 02 Mar 2021 17:38:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHDeU-0007gB-V1 for bug-gnu-emacs@gnu.org; Tue, 02 Mar 2021 17:38:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42924) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lHDeU-0006Ka-Ip for bug-gnu-emacs@gnu.org; Tue, 02 Mar 2021 17:38:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lHDeU-0001Bw-Ft for bug-gnu-emacs@gnu.org; Tue, 02 Mar 2021 17:38:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 02 Mar 2021 22:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46859 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 46859-submit@debbugs.gnu.org id=B46859.16147246414533 (code B ref 46859); Tue, 02 Mar 2021 22:38:02 +0000 Original-Received: (at 46859) by debbugs.gnu.org; 2 Mar 2021 22:37:21 +0000 Original-Received: from localhost ([127.0.0.1]:54470 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lHDdp-0001B2-JT for submit@debbugs.gnu.org; Tue, 02 Mar 2021 17:37:21 -0500 Original-Received: from mail-wr1-f46.google.com ([209.85.221.46]:35165) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lHDdm-0001An-Qm for 46859@debbugs.gnu.org; Tue, 02 Mar 2021 17:37:20 -0500 Original-Received: by mail-wr1-f46.google.com with SMTP id l12so21558463wry.2 for <46859@debbugs.gnu.org>; Tue, 02 Mar 2021 14:37:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=eUYonnpzxtQqtiTFzlyrxWIzWhGKce5o2bVb6/cGDwI=; b=fG+02pkVeKSxf2XtJwZhW4UMoGo8pqRT7xs+uuzqV6hTqeTrhSimSunEfI5qJity+A QSOCr5qfXUbmgu70EAcrWj4NSXUyrcxrYFaag+KDEFDTITQdrEcdA0oT2xjx4o4lHZUx kmqlnlKgz6Xj7g/y1F+sVsXtr8tz61FnRFxcev94hPJHhJui0WKwjoF9emN5eNk5igi8 2zrO4Fw19hZACIGLGVO+sllRegULTzvh0nxDRgpv1W1g2rpgEFqO2GIgIImJQj8q3ql8 gvv/XG8an75sPjtxXZX4kt5KYtG3tC7yonlFekgdmzF+BU8jBlHOcU65BiRbv2WgohBd gtXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=eUYonnpzxtQqtiTFzlyrxWIzWhGKce5o2bVb6/cGDwI=; b=r51YGjqhTACrWp/sCTp8aKxlDYiGthMC6mGJT8tjhH5m/n9g4OQn+pzCj9AhLorwJ/ eqvmOJNeBXH87iMIftlBOcm8s2t8m5VoDTs0tHOuH5mw8Womrv1hrcKTyByqHzJUD+D/ Eyv0anQFwK8qauiQQHY/v7mJb5T69Ra2Iid58olZGoBsw9+4O2de7V8YCagEHBTx402S NvB53crsXcvF99DgUv4abGG39PUYXi3mrkQCjTqjirbaExjBzCtpWtmzzBXYhFe0Oo+k YhH+1V9cDEn57o3fZRNU+NK32J99oFZz4U3T4c1Vswpm6pURAxH2PX19eGokh7YTGQtP FQlA== X-Gm-Message-State: AOAM5339DLPSTIUSNqAJwS6i8PWlqOv2T4KQd1ba33gbVscIvSbg8lt/ t6WrjCoGxYb1tFwWLZK1A1JJKQBx89M= X-Google-Smtp-Source: ABdhPJxM/unBl4msrM9a2vHFdOzPG43578iSw7rDRpGv03xuceUZi8SBq/HAnV1EhhcbrnaVZKhpEA== X-Received: by 2002:adf:ed06:: with SMTP id a6mr18120970wro.208.1614724632858; Tue, 02 Mar 2021 14:37:12 -0800 (PST) Original-Received: from [192.168.0.6] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id g17sm28700727wru.60.2021.03.02.14.37.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Mar 2021 14:37:12 -0800 (PST) In-Reply-To: Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:201246 Archived-At: On 03.03.2021 00:14, Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors wrote: > I'm interested in seeing if I could gain some more > performance by short circuiting after the first iteration of a match on > the same line. In my test scenario there are a lot of matches on the > same huge line. What do you think? You probably mean to short-circuit as soon as you reach the target column (there might be multiple matches within those 500 chars), skipping the rest of the matches on the same line. Sounds worth a try. Another approach would be to truncate the line sometime earlier, like: diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 18fdd963fb..63a17a8521 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -1531,7 +1531,10 @@ xref-matches-in-files (while (re-search-forward grep-re nil t) (push (list (string-to-number (match-string line-group)) (match-string file-group) - (buffer-substring-no-properties (point) (line-end-position))) + (buffer-substring-no-properties (point) + (min + (+ (point) 500) + (line-end-position)))) hits))) (xref--convert-hits (nreverse hits) regexp))) ...of course, ideally we would keep all contents of the line somewhere in memory and truncate with (setq truncate-line t). But IIRC Juri said this didn't give us as much of a speedup as we'd want. Another question: how many hits do you usually have in that huge one-line file? If it's more than 2-3, it might be that our current algorithm which creates "match objects" will duplicate this string unnecessarily N times (which is the number of hits), in xref--collect-matches-1, to then cut it up and merge into one line again when printing the buffer. In which case the patch above should also show a healthy improvement, but we could figure out something better instead. Anyway, please benchmark your "earlier short-circuit" approach and then the above patch too.