From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.bugs Subject: bug#66117: 30.0.50; `find-buffer-visiting' is slow when opening large number of buffers Date: Sat, 30 Dec 2023 10:39:49 +0000 Message-ID: <87frzkas96.fsf@localhost> References: <878r919qfh.fsf@localhost> <87lecp84mf.fsf@localhost> <83ttrdx8j9.fsf@gnu.org> <87a5su261p.fsf@localhost> <838r8e24yy.fsf@gnu.org> <87y1gezspg.fsf@localhost> <834jj21z05.fsf@gnu.org> <87il7izo4l.fsf@localhost> <831qe61xrh.fsf@gnu.org> <87cyxqzmhh.fsf@localhost> <83zg0uzlgw.fsf@gnu.org> <87v8bhxzcu.fsf@localhost> <83sf3te1tu.fsf@gnu.org> <87msu1qmqv.fsf@localhost> <83zfy1cgoa.fsf@gnu.org> <87le9lcg4e.fsf@localhost> <831qb578n2.fsf@gnu.org> <87zfxt3yfy.fsf@localhost> <83jzow3yf1.fsf@gnu.org> <83h6k03tpx.fsf@gnu.org> <83frzk3srq.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23001"; mail-complaints-to="usenet@ciao.gmane.io" Cc: dmitry@gutov.dev, 66117@debbugs.gnu.org, monnier@iro.umontreal.ca To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 30 11:37:16 2023 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 1rJWiR-0005oK-Lw for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 30 Dec 2023 11:37:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJWiF-00011Z-SB; Sat, 30 Dec 2023 05:37:03 -0500 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 1rJWiE-00011O-CP for bug-gnu-emacs@gnu.org; Sat, 30 Dec 2023 05:37:02 -0500 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 1rJWiE-0008DF-3g for bug-gnu-emacs@gnu.org; Sat, 30 Dec 2023 05:37:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rJWiE-0005YM-6f for bug-gnu-emacs@gnu.org; Sat, 30 Dec 2023 05:37:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ihor Radchenko Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 30 Dec 2023 10:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66117 X-GNU-PR-Package: emacs Original-Received: via spool by 66117-submit@debbugs.gnu.org id=B66117.170393261121329 (code B ref 66117); Sat, 30 Dec 2023 10:37:02 +0000 Original-Received: (at 66117) by debbugs.gnu.org; 30 Dec 2023 10:36:51 +0000 Original-Received: from localhost ([127.0.0.1]:43086 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rJWi2-0005Xx-JY for submit@debbugs.gnu.org; Sat, 30 Dec 2023 05:36:51 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:38231) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rJWi0-0005Xj-8Q for 66117@debbugs.gnu.org; Sat, 30 Dec 2023 05:36:49 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 17AE5240101 for <66117@debbugs.gnu.org>; Sat, 30 Dec 2023 11:36:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1703932602; bh=KD6QDpcDFE7Bz03BU/JkgYJiKa/I4pEHX9JcDpfWuQI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=qqFcYlWmWLertoxzknKOYMqS9QL5n88zzZdB9BP185AGqYLTX58tP+h8zh+tc3QK6 TCrrCINjBh2gUB3LCl5q8DqC5+SbsT4SJMy6zCPNsX5rOfbwz01nkr7eZYwtJM60yS pdSJhcsSMLJSpu1TIfSyGCj9ptkQ/yyqb3S4p/W4TE1L05AWXxqnUpZWra7elnjSPx RMabtzdsNC2NHsZKGMviULf0b+ZfMcV8f2edU9z6Fq3LiRZhcglWnNCu+c3hGUyrgS nBeWV16CxE0z6PVSnGpWGbhvSqET5ZWsFrw9dr7Hqag+5rM/kF+jd4ljey5xqRdcfU kpldESxG19hgw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4T2JZc34xbz6tw9; Sat, 30 Dec 2023 11:36:40 +0100 (CET) In-Reply-To: <83frzk3srq.fsf@gnu.org> 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:277073 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> Ehmm... I see that test/src/buffer-tests now have 5 failures that >> were not there before: >> >> 5 unexpected results: >> FAILED test-buffer-modifications >> FAILED test-kill-buffer-auto-save-default >> FAILED test-kill-buffer-auto-save-delete-no >> FAILED test-kill-buffer-auto-save-delete-yes >> FAILED test-restore-buffer-modified-p >> >> Also, 7 of the lisp/files-test fail: >> >> 7 unexpected results: >> FAILED files-tests-bug-18141 >> FAILED files-tests-file-name-non-special-make-auto-save-file-name >> FAILED files-tests-file-name-non-special-set-visited-file-modtime >> FAILED files-tests-no-file-write-contents >> FAILED files-tests-revert-buffer >> FAILED files-tests-revert-buffer-with-fine-grain >> FAILED files-tests-zzdont-rewrite-precious-files >> >> Could you please look into these? (Interestingly, those 5+7 don't >> fail for me on MS-Windows, only on GNU/Linux...) FYI, all the tests are passing on my side (GNU/Linux): cd test make src/buffer-tests Ran 406 tests, 406 results as expected, 0 unexpected (2023-12-30 11:24:04+0100, 0.464788 sec) > I think at least part of the problem is in this fragment from > find-file-noselect: > > ;; Find any buffer for a file that has same truename. > (other (and (not buf) > (find-buffer-visiting > filename > ;; We want to filter out buffers that we've > ;; visited via symlinks and the like, where > ;; the symlink no longer exists. > (lambda (buffer) > (let ((file (buffer-local-value > 'buffer-file-name buffer))) > (and file (file-exists-p file)))))))) Not this one - (and file ...) will never trigger when file is nil. > Test test-buffer-modifications backtrace: > file-exists-p(nil) > find-buffer-visiting("/tmp/emacs-test-MzitxT-buffer" #f(compiled-fun > find-file-noselect("/tmp/emacs-test-MzitxT-buffer" nil nil nil) > find-file("/tmp/emacs-test-MzitxT-buffer") > > Please attend to this as soon as you can, because I think this same > problem will break many other use cases. I think I found the problem - it is rather silly. See the attached patch. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-find-buffer-visiting-Fix-test-breakage-introduced-in.patch >From 0edc966cd7e2b9c2ce3af44a4a72e6f467eaf713 Mon Sep 17 00:00:00 2001 Message-ID: <0edc966cd7e2b9c2ce3af44a4a72e6f467eaf713.1703932575.git.yantar92@posteo.net> From: Ihor Radchenko Date: Sat, 30 Dec 2023 11:31:51 +0100 Subject: [PATCH] find-buffer-visiting: Fix test breakage introduced in b7a737ef49 * lisp/files.el (find-buffer-visiting): Fix code branch checking for buffers referring to the same file number. We should check the found buffer with the file number, not current. Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=66117#412 --- lisp/files.el | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index 315ba831e8..78e2bca3cf 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -2220,15 +2220,17 @@ find-buffer-visiting (number (file-attribute-file-identifier attributes))) (and buffer-file-numbers-unique (car-safe number) ;Make sure the inode is not just nil. - (let ((buf (find-buffer 'buffer-file-number number))) - (when (and buf (buffer-local-value 'buffer-file-name buf) + (let* ((buf (find-buffer 'buffer-file-number number)) + (buf-file-name (and buf (buffer-local-value 'buffer-file-name buf)))) + (when (and buf-file-name ;; Verify this buffer's file number ;; still belongs to its file. - (file-exists-p buffer-file-name) - (equal (file-attributes buffer-file-truename) - attributes) + (file-exists-p buf-file-name) + (equal + (file-attributes (buffer-local-value 'buffer-file-truename buf)) + attributes) (or (not predicate) - (funcall predicate (current-buffer)))) + (funcall predicate buf))) buf)))))))) -- 2.42.0 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--