unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 51143@debbugs.gnu.org, Eduardo Ochs <eduardoochs@gmail.com>
Subject: bug#51143: 29.0.50; Long delay after M-x commandname
Date: Tue, 04 Oct 2022 00:40:54 +0200	[thread overview]
Message-ID: <87a66czg21.fsf@web.de> (raw)
In-Reply-To: <87y1uldl1t.fsf@web.de> (Michael Heerdegen's message of "Thu, 15 Sep 2022 11:49:34 +0200")

[-- Attachment #1: Type: text/plain, Size: 251 bytes --]

Michael Heerdegen <michael_heerdegen@web.de> writes:

> I remember what I had discussed with Stefan.  The uncontroversial part
> was to factor out the `commandp' tests out of
> `completion-try-completion'.
>
> I'll have a look.

This is what I have:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Try-to-speed-up-extended-command-shorthand-computati.patch --]
[-- Type: text/x-diff, Size: 1763 bytes --]

From 6bc974197ff3e191971f933cc7f6fd952cdbba86 Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <michael_heerdegen@web.de>
Date: Sun, 18 Sep 2022 12:26:53 +0200
Subject: [PATCH] Try to speed up extended command shorthand computation

* lisp/simple.el (execute-extended-command--shorter): Compute a
complete list of `commandp' symbols once.  This significantly speeds
up complicated cases while the slowdown of simple cases is still
accetable.
---
 lisp/simple.el | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 10a610e0c6..6724f3d6fc 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2465,9 +2465,13 @@ execute-extended-command--shorter-1

 (defun execute-extended-command--shorter (name typed)
   (let ((candidates '())
+        commands
         (max (length typed))
         (len 1)
         binding)
+    ;; Precompute a list of commands once to avoid repeated `commandp' testing
+    ;; of symbols in the `completion-try-completion' call inside the loop below
+    (mapatoms (lambda (s) (when (commandp s) (push s commands))))
     (while (and (not binding)
                 (progn
                   (unless candidates
@@ -2480,8 +2484,8 @@ execute-extended-command--shorter
       (input-pending-p)    ;Dummy call to trigger input-processing, bug#23002.
       (let ((candidate (pop candidates)))
         (when (equal name
-                       (car-safe (completion-try-completion
-                                  candidate obarray 'commandp len)))
+                     (car-safe (completion-try-completion
+                                candidate commands nil len)))
           (setq binding candidate))))
     binding))

--
2.30.2


[-- Attachment #3: Type: text/plain, Size: 374 bytes --]


This speeds up computations of extended command shortcuts by a factor of
around 4 in the complicated cases, while the slowdown for the easy cases
is hardly noticeable.  Maybe Eduardo can give that a try?

Further improvements are probably not that low-hanging fruits.  The
calculation is also always interruptible so I don't think more work is
worth the trouble.

Michael.

  reply	other threads:[~2022-10-03 22:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-12  2:44 bug#51143: 29.0.50; Long delay after M-x commandname Eduardo Ochs
2021-10-12 12:56 ` Lars Ingebrigtsen
2021-10-12 19:05   ` Eduardo Ochs
2021-10-12 19:19     ` Lars Ingebrigtsen
2021-11-29 19:25       ` Lars Ingebrigtsen
2021-11-29 20:11         ` Michael Heerdegen
2021-11-29 20:13           ` Lars Ingebrigtsen
2022-09-12 11:50           ` Lars Ingebrigtsen
2022-09-15  9:49             ` Michael Heerdegen
2022-10-03 22:40               ` Michael Heerdegen [this message]
2022-10-03 23:33                 ` Lars Ingebrigtsen
2022-10-09 18:53                   ` Michael Heerdegen
2021-10-12 13:39 ` Eli Zaretskii
2021-10-12 15:55   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a66czg21.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=51143@debbugs.gnu.org \
    --cc=eduardoochs@gmail.com \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).