From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#48738: [PATCH] Optimized `describe-variable' predicate Date: Mon, 31 May 2021 06:55:21 +0200 Message-ID: <87h7ijmrie.fsf@gnus.org> References: <55a7f6fc-ccad-a8e3-2f51-1cbc1555a4f8@daniel-mendler.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36611"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 48738@debbugs.gnu.org To: Daniel Mendler Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon May 31 06:56:11 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 1lnZyE-0009Lc-UA for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 31 May 2021 06:56:10 +0200 Original-Received: from localhost ([::1]:43140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnZyD-00029i-U9 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 31 May 2021 00:56:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35826) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnZy6-00026K-D3 for bug-gnu-emacs@gnu.org; Mon, 31 May 2021 00:56:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49170) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lnZy6-0002MK-3Q for bug-gnu-emacs@gnu.org; Mon, 31 May 2021 00:56:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lnZy6-0002Yv-21 for bug-gnu-emacs@gnu.org; Mon, 31 May 2021 00:56:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 31 May 2021 04:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48738 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 48738-submit@debbugs.gnu.org id=B48738.16224369349783 (code B ref 48738); Mon, 31 May 2021 04:56:02 +0000 Original-Received: (at 48738) by debbugs.gnu.org; 31 May 2021 04:55:34 +0000 Original-Received: from localhost ([127.0.0.1]:60713 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lnZxd-0002Xj-RQ for submit@debbugs.gnu.org; Mon, 31 May 2021 00:55:34 -0400 Original-Received: from quimby.gnus.org ([95.216.78.240]:55276) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lnZxb-0002XO-Kr for 48738@debbugs.gnu.org; Mon, 31 May 2021 00:55:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=LggVghrdhhtwTX17ZLgpG/ueyS1g0YVsQIpRIyfVXXk=; b=Wb9ElXF9A+NE3Pi5jyzmqdvHUp Q3reof/1jkLiQA3LVzumM8lzmsPHCgpPZ+nzoXBkK0NDShfj6kmHQXkQUMGkrhsX6pAtjAtne75Ve /sH0zWpay8OAWtK4G49lBA1deUzTZmHfp2VMAxwZajqdGOB71BgIGwlku/VnIHkByHoA=; Original-Received: from cm-84.212.220.105.getinternet.no ([84.212.220.105] helo=xo) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lnZxS-0005bE-Kr; Mon, 31 May 2021 06:55:25 +0200 X-Now-Playing: Zonal's _Wrecked_: "No Investigation" In-Reply-To: <55a7f6fc-ccad-a8e3-2f51-1cbc1555a4f8@daniel-mendler.de> (Daniel Mendler's message of "Sun, 30 May 2021 06:27:16 +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" Xref: news.gmane.io gmane.emacs.bugs:207653 Archived-At: Daniel Mendler writes: > Do not switch to the original buffer. Use `buffer-local-value` > instead. The buffer switching is more costly, which slows down > continuously updating completion UIs like Icomplete or Vertico if > there are many variables. Thanks; applied to Emacs 28 with some changes -- I thought the `ignore-errors' logic was kinda unclear, so I rewrote that bit using an explicit `condition-case' checking for the error thrown in this case. Adjusted patch included below; hopefully I didn't introduce any errors here... > Ideally there would be a `buffer-local-boundp` predicate we could use > here. Yes, that would be nice, I think. And we probably have a lot of code in Emacs that uses `with-current-buffer' instead of `buffer-local-value' that could be similarly optimised (but I guess it mostly only makes sense to do so when it's called in an intensive loop like here). diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 666583db72..c8f078cb85 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -1024,12 +1024,15 @@ describe-variable (format-prompt "Describe variable" (and (symbolp v) v)) #'help--symbol-completion-table (lambda (vv) - ;; In case the variable only exists in the buffer - ;; the command we switch back to that buffer before - ;; we examine the variable. - (with-current-buffer orig-buffer - (or (get vv 'variable-documentation) - (and (boundp vv) (not (keywordp vv)))))) + (or (get vv 'variable-documentation) + (and (not (keywordp vv)) + ;; Since the variable may only exist in the + ;; original buffer, we have to look for it + ;; there. + (condition-case nil + (buffer-local-value vv orig-buffer) + (:success t) + (void-variable nil))))) t nil nil (if (symbolp v) (symbol-name v)))) (list (if (equal val "") -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no