Subject: bug#23002: 25.0.92; sluggish M-x

From: YAMAMOTO Mitsuharu <[email-masked]>
Date: Tue, 15 Mar 2016 17:14:46 +0900

>>>>> On Mon, 14 Mar 2016 12:21:54 +0800, Leo Liu <[email-masked]> said:

> On 2016-03-13 18:08 +0200, Eli Zaretskii wrote:
>> I cannot reproduce this on my system.  (You didn't say which system is
>> yours, nor which commit is was built from, so I cannot compare that.)
>> Here, the cursor exits the minibuffer immediately, and if I type
>> something, the hint message is never shown (as I'd expect).
>> 
>> Sounds like sit-for is not working correctly on your system, but I
>> have no idea why that should happen.

> At the time of reporting I didn't have access to a NS build. I just did
> one and couldn't reproduce it either. I have emailed MacPort maintainer
> to take a look at this bug and will act accordingly. Thanks.

Not updating the display on the Mac port is because it avoids frequent
flushes and input reads for overall performance.  Flushing is deferred
until the next input reading, and in the case that
execute-extended-command--shorter takes a long time, it will be at the
timing of the next polling (every 2 seconds by default).

However, the sluggishness during the evaluation of
execute-extended-command--shorter is common to the both ports on OS X,
or non-interrupt-driven systems that use polling with SIGALRM for
quit/while-no-input handling, in general.  I'm thinkng about applying
the following patch to the Mac port, but it might also be useful for
other systems.

				     YAMAMOTO Mitsuharu
				[email-masked]

diff --git a/lisp/simple.el b/lisp/simple.el
index 4954763..57b7ca6 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1642,6 +1642,7 @@ execute-extended-command--shorter
   (let ((candidates '())
         (max (length typed))
         (len 1)
+        (use-polling (and (null (car (current-input-mode))) throw-on-input))
         binding)
     (while (and (not binding)
                 (progn
@@ -1652,6 +1653,11 @@ execute-extended-command--shorter
                   ;; Don't show the help message if the binding isn't
                   ;; significantly shorter than the M-x command the user typed.
                   (< len (- max 5))))
+      ;; On non-interrupt-driven systems, while-no-input polls for
+      ;; input every `polling-period' (default 2) seconds, and that is
+      ;; not frequent enough.  So we call input-pending-p manually.
+      (if (and use-polling (input-pending-p))
+          (signal 'quit nil))
       (let ((candidate (pop candidates)))
         (when (equal name
                        (car-safe (completion-try-completion