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: Tue, 12 Dec 2023 16:33:05 +0000 Message-ID: <87plzbxtxa.fsf@localhost> References: <878r919qfh.fsf@localhost> <83zg1d468w.fsf@gnu.org> <87bkdr2651.fsf@localhost> <87pm2584oz.fsf@localhost> <83cyy11ln1.fsf@gnu.org> <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> <83y1gdxws8.fsf@gnu.org> <87jzrwm7ul.fsf@localhost> <87h6n0m781.fsf@localhost> <87v8935wik.fsf@localhost> <83msuftr0i.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13731"; mail-complaints-to="usenet@ciao.gmane.io" Cc: dmitry@gutov.dev, 66117@debbugs.gnu.org, Stefan Monnier To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Dec 12 17:31:47 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 1rD5fe-0003Lb-LZ for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 12 Dec 2023 17:31:46 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rD5es-0001tS-Dy; Tue, 12 Dec 2023 11:30:58 -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 1rD5ej-0001Si-SD for bug-gnu-emacs@gnu.org; Tue, 12 Dec 2023 11:30:51 -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 1rD5eh-0007Pz-3I for bug-gnu-emacs@gnu.org; Tue, 12 Dec 2023 11:30:49 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rD5ew-0001l2-07 for bug-gnu-emacs@gnu.org; Tue, 12 Dec 2023 11:31: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: Tue, 12 Dec 2023 16:31:01 +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.17023986276713 (code B ref 66117); Tue, 12 Dec 2023 16:31:01 +0000 Original-Received: (at 66117) by debbugs.gnu.org; 12 Dec 2023 16:30:27 +0000 Original-Received: from localhost ([127.0.0.1]:57314 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rD5eN-0001kD-09 for submit@debbugs.gnu.org; Tue, 12 Dec 2023 11:30:27 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]:38371) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rD5eK-0001jx-GZ for 66117@debbugs.gnu.org; Tue, 12 Dec 2023 11:30:25 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 67C7B240028 for <66117@debbugs.gnu.org>; Tue, 12 Dec 2023 17:30:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1702398603; bh=9Lf++1gw/KRRPoDzqqmh9AAC+B6o+OUF87A/K04OCqE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=OayIsB1gmp8H0OqLTdCKbjfQFT6tu+TiDMt2Up8ZyfBjnN33gOcj7QcF1ieErH+0A N9QODJftaEAl+5Tn1dNMxyl/I4KiqEZesR6ug8L4P94gX2uWnL+2mJe0rkCOcMoB2Z 9JbEhbNP+RZPqXdQbbtSgVHCyyl+5e0qOBdzWYnjKfelrNSfo9ayoEPg9GIkBbfzKH xK/TqFUePTxzO+QEdJtKCowRjTLwuuTAnZ1TFVTfhN1Uv6iIFOd3UzvH4P94JaBLRv kcEX91AgGeHHkyqrBhTSkUaouxNFQcPsU7Ko0IKRQ7W/SShQ/3YLlEWySh6oCXu9xI JDpgPm2QXrGbw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4SqPGf0cxzz6tyB; Tue, 12 Dec 2023 17:30:01 +0100 (CET) In-Reply-To: <83msuftr0i.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:276059 Archived-At: Eli Zaretskii writes: >> What do you think about introducing something like >> >> struct buffer buffer_overrides; >> >> It will be similar to buffer_defaults in buffer.c, but will hold the >> overriding values of buffer-local variables that are to be used instead >> of proper buffer-local variables. That way, we can speed up let-binding >> of case-fold-search. > > I'm sorry, I don't think I understand how this will work and avoid the > problems we have with let-binding. So I added Stefan, in the hope > that he might understand what I am evidently missing. Let me elaborate. - In eval.c, `Flet' always uses `specbind' to bind `case-fold-search'. Because `case-fold-search' is declared special (u.s.declared_special = true). - For `case-fold-search', `specbind' does /* If SYMBOL is a per-buffer variable which doesn't have a buffer-local value here, make the `let' change the global value by changing the value of SYMBOL in all buffers not having their own value. This is consistent with what happens with other buffer-local variables. */ if (NILP (Flocal_variable_p (symbol, Qnil))) specpdl_ptr->let.kind = SPECPDL_LET_DEFAULT; - Later, `specbind' calls `do_specbind' where SPECPDL_LET_DEFAULT causes a call to `set_default_internal'. - Then, `set_default_internal', for any variable with positive buffer_local_flags loops over all the live buffers to overwrite the buffer-local value. This loop is the bottleneck, making let-binding of `case-fold-search' (and any other variable marked in buffer.c:4691 block) scale with the number of open buffers. - What I propose is to avoid this loop in `do_specbind' altogether. Instead of having to loop through all the buffers to set temporary buffer-local value, I propose to introduce special buffer object `buffer_overrides' that will hold such temporary bindings. Then, we can change BVAR to something like #define BVAR(buf, field) (buffer_overrides->field ## _ == UNSET ?\ (buf)->field ## _ :\ buffer_overrides->field ## _) and replace the loop with simply setting buffer_overrides slot. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at