From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#66117: 30.0.50; `find-buffer-visiting' is slow when opening large number of buffers Date: Wed, 13 Dec 2023 09:12:39 -0500 Message-ID: References: <878r919qfh.fsf@localhost> <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> <87plzbxtxa.fsf@localhost> <87y1dzvvf0.fsf@localhost> <83plzas3pg.fsf@gnu.org> <87r0jqw8u9.fsf@localhost> <83jzpis08a.fsf@gnu.org> <87il52w744.fsf@localhost> <83fs06rz10.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20627"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: dmitry@gutov.dev, Ihor Radchenko , 66117@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 13 15:14:12 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 1rDQ04-0005Bb-H2 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 13 Dec 2023 15:14:12 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rDPzg-0005BH-Gp; Wed, 13 Dec 2023 09:13:48 -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 1rDPzf-0005Ay-0m for bug-gnu-emacs@gnu.org; Wed, 13 Dec 2023 09:13:47 -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 1rDPze-0004So-OK for bug-gnu-emacs@gnu.org; Wed, 13 Dec 2023 09:13:46 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rDPzu-0007Tj-C4 for bug-gnu-emacs@gnu.org; Wed, 13 Dec 2023 09:14:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 13 Dec 2023 14:14: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.170247678828632 (code B ref 66117); Wed, 13 Dec 2023 14:14:02 +0000 Original-Received: (at 66117) by debbugs.gnu.org; 13 Dec 2023 14:13:08 +0000 Original-Received: from localhost ([127.0.0.1]:58463 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rDPz1-0007Rh-Mx for submit@debbugs.gnu.org; Wed, 13 Dec 2023 09:13:07 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:17098) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rDPyx-0007R0-9L for 66117@debbugs.gnu.org; Wed, 13 Dec 2023 09:13:06 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 197E580793; Wed, 13 Dec 2023 09:12:41 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1702476760; bh=fQ/rKTC9Ju+MKnXQL7E3I6Jh9XPSxOjznEfk01l6NmQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=hQ3qBcfsQ/hQ1FGqh3e/cMXBEAwU0KwrstKClX+vwvsRCsjsHM4CVff70FcfgHw7K uyFOD2P9a7w2vExTNCa2hnLCJzEWRgBTvdJanDtlkeifs16L1TcpteTwFZ3iScUOon a4DhIM5Ub0vITngvWfbSVHcImqk8JS4lw0r+M22G7htFgiOPskWDqD0iGBg5olaz0U 915wEEwnCD6ShwAsVG3/wME5NwAyaUjyLZZEOYDNLVBhZ2eNhKkP2WEg6BfyIQGaYq 6Gm6XtLObhvf1KB9Bh2Uwo52LO0vxLh/JV/G1h7vWJFYuOLcAz5pxQ3i8/Uh8f5Iv0 jHbZW1Fvd5rLw== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 03A46801D4; Wed, 13 Dec 2023 09:12:40 -0500 (EST) Original-Received: from pastel (unknown [45.72.203.88]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id CADBC1201E7; Wed, 13 Dec 2023 09:12:39 -0500 (EST) In-Reply-To: <83fs06rz10.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 13 Dec 2023 15:51:39 +0200") 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:276134 Archived-At: >> But it will only solve specific problem with `find-buffer-visiting' and >> we can always go for it if we cannot find anything better. > Which other popular functions need to loop through all the buffers in > Lisp? Not sure why that matters. The performance problem comes from repeated uses of `(let ((case-fold-search ..)) ...)` where the repetition can be due to anything (not only enumerating buffers). The "loop through buffers" happens when entering and leaving the `let`, because it has to `set/unset` the corresponding filed of the `struct buffer` of all the buffers whose `case-fold-search` is "global". Making it a DEFVAR_LISP rather than a DEFVAR_PER_BUFFER will fix this problem (at the cost of making it less efficient to `set-buffer` when that variable has been made buffer-local). DEFVAR_PER_BUFFER should be for variables which are usually buffer-local, and apparently that's not the case of `case-fold-search`, so I'm starting to think that changing it from DEFVAR_PER_BUFFER to DEFVAR_LISP might be the better option. Stefan