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#53749: 29.0.50; [PATCH] Xref backend for TeX buffers Date: Wed, 15 May 2024 00:24:24 +0300 Message-ID: <82993b86-0f34-4adb-a392-c74db5176d14@yandex.ru> References: <2c5c8afa-b57e-3156-d21c-5523cacb4d87@yandex.ru> <831qf1mgjl.fsf@gnu.org> <87cyyj9rpp.fsf@gnu.org> <65793.1694843596@localhost> <83ba27b7-4d28-4a3f-b803-4bc49f62986c@yandex.ru> 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="35905"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: 53749@debbugs.gnu.org, Ikumi Keita , David Fussner , Arash Esbati , stefankangas@gmail.com, Tassilo Horn , Eli Zaretskii To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 14 23:26:27 2024 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 1s6zfG-0009A4-W2 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 14 May 2024 23:26:27 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6zes-0004Hl-3J; Tue, 14 May 2024 17:26:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s6zer-0004Hb-1Z for bug-gnu-emacs@gnu.org; Tue, 14 May 2024 17:26:01 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s6zeq-0003b6-P2 for bug-gnu-emacs@gnu.org; Tue, 14 May 2024 17:26:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s6zer-0005Uk-Vx for bug-gnu-emacs@gnu.org; Tue, 14 May 2024 17:26:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 14 May 2024 21:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53749 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: pending patch Original-Received: via spool by 53749-submit@debbugs.gnu.org id=B53749.171572191121098 (code B ref 53749); Tue, 14 May 2024 21:26:01 +0000 Original-Received: (at 53749) by debbugs.gnu.org; 14 May 2024 21:25:11 +0000 Original-Received: from localhost ([127.0.0.1]:41479 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s6ze2-0005UE-R1 for submit@debbugs.gnu.org; Tue, 14 May 2024 17:25:11 -0400 Original-Received: from forward501c.mail.yandex.net ([178.154.239.209]:44302) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s6zdz-0005U7-2B for 53749@debbugs.gnu.org; Tue, 14 May 2024 17:25:09 -0400 Original-Received: from mail-nwsmtp-smtp-production-main-85.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-85.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:b1a0:0:640:e983:0]) by forward501c.mail.yandex.net (Yandex) with ESMTPS id AFBB461424; Wed, 15 May 2024 00:24:34 +0300 (MSK) Original-Received: by mail-nwsmtp-smtp-production-main-85.iva.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id TOnPHUBCZa60-ub8Hks1u; Wed, 15 May 2024 00:24:33 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1715721873; bh=npKb8gXDgTKlxOOUWnPSoA4Xqz7JZyfV9PZP59i2DFs=; h=In-Reply-To:From:Subject:Message-ID:Cc:References:Date:To; b=FyMU2wrsLornY5Jg6N70A4afp4cydLaQi8vLJiEu/b6RoMOBJ5tdjOdSXzxl9X7rS bFhCgDa8fTjixrK+aLXZF/y29iyg2MUZHiEQbs2+bSRCQfvEQgEtuDnrW9SBUTA9EL e2qJY2LWqbYcJxbh6Anzc+uWylckXkrQI1medGoU= Authentication-Results: mail-nwsmtp-smtp-production-main-85.iva.yp-c.yandex.net; dkim=pass header.i=@yandex.ru Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfauth.nyi.internal (Postfix) with ESMTP id 543DB1200032; Tue, 14 May 2024 17:24:29 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 14 May 2024 17:24:29 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegiedgudehlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfevfhfhjggtgfesthejredttddvjeenucfhrhhomhepffhm ihhtrhihucfiuhhtohhvuceoughguhhtohhvseihrghnuggvgidrrhhuqeenucggtffrrg htthgvrhhnpeefleffhfejhfeghedtfeehtdeiheekheetteefleejkefhgeetiedvhefg jeeuveenucffohhmrghinhepghhnuhdrohhrghenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpegughhuthhovhdomhgvshhmthhprghuthhhphgv rhhsohhnrghlihhthidqudeffeefleelheehvddqvdelgeejjeejjeeiqdgughhuthhovh eppeihrghnuggvgidrrhhusehfrghsthhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: ib1d9465d:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 14 May 2024 17:24:26 -0400 (EDT) Content-Language: en-US In-Reply-To: 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:285054 Archived-At: On 13/05/2024 23:54, Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors wrote: >> For now, I've pushed a fix in 86187d43e2d which seems to handle David's >> scenario and address your review comment as well. > > The let-binding is done outside of `with-current-buffer`, so it relies > on the fact (itself problematic) that `inhibit-modification-hooks` is > not buffer-local. Good point. > Would it be OK to use a patch like the one below? Sure, thank you. Pushed. > IIUC, in the `syntax-needed` case, the let-binding of > `inhibit-modification-hooks` is just not useful very (4-7% is not worth > the trouble), so its purpose is to speed up the other case. 4-10% is the improvement for both cases (the "syntax needed" and not). I could be on the fence whether it's "not useful" - on the one hand 4% might not sound like much - on the other we already have this bit of improvement which has no known bugs. And when you combine a few of such performance hacks, the difference gets more noticeable. Also, I'm eyeing another performance improvement (simplifying file type detection) - the call to set-auto-mode is not fast. Simply commenting this call out improves the performance by 4x or so - but we'll need a simpler version of it instead, of course. And with the above change (commenting out the set-auto-mode call), the difference that the inhibit-modification-hooks hack makes is amplified: it can get up to 20%. Ultimately it'll be somewhere in between, but this sounds better, right? > Also, what about the other two bindings of `inhibit-modification-hooks`? The other two are used while the contents of the Xref buffer are printed (or re-printed), so there's none of the syntax-ppss complications there. The performance difference is 8.5% in my last measurement. > > Stefan > > > diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el > index f9faec1b474..214e9cb6c09 100644 > --- a/lisp/progmodes/xref.el > +++ b/lisp/progmodes/xref.el > @@ -1282,7 +1282,7 @@ xref--show-common-initialize > (erase-buffer) > (setq overlay-arrow-position nil) > (xref--insert-xrefs xref-alist) > - (add-hook 'post-command-hook 'xref--apply-truncation nil t) > + (add-hook 'post-command-hook #'xref--apply-truncation nil t) > (goto-char (point-min)) > (setq xref--original-window (assoc-default 'window alist) > xref--original-window-intent (assoc-default 'display-action alist)) > @@ -2112,10 +2112,7 @@ xref--convert-hits > (defun xref--collect-matches (hit regexp tmp-buffer syntax-needed) > (pcase-let* ((`(,line ,file ,text) hit) > (file (and file (concat xref--hits-remote-id file))) > - (buf (xref--find-file-buffer file)) > - ;; This is fairly dangerouns, but improves performance > - ;; for large lists, see https://debbugs.gnu.org/53749#227 > - (inhibit-modification-hooks t)) > + (buf (xref--find-file-buffer file))) > (if buf > (with-current-buffer buf > (save-excursion > @@ -2130,6 +2130,9 @@ > ;; Using the temporary buffer is both a performance and a buffer > ;; management optimization. > (with-current-buffer tmp-buffer > + ;; This let is fairly dangerouns, but improves performance > + ;; for large lists, see https://debbugs.gnu.org/53749#227 > + (let ((inhibit-modification-hooks t)) > (erase-buffer) > (when (and syntax-needed > (not (equal file xref--temp-buffer-file-name))) > @@ -2144,7 +2147,7 @@ > (setq-local xref--temp-buffer-file-name file) > (setq-local inhibit-read-only t) > (erase-buffer)) > - (insert text) > + (insert text)) > (goto-char (point-min)) > (when syntax-needed > (syntax-ppss-flush-cache (point))) > > > >