Subject: Re: bug#73473: 31.0.50; Minibuffer completions include nonsense prefix candidates

From: Stefan Monnier <[email-masked]>
Date: Fri, 27 Sep 2024 11:35:00 -0400

> AFAICT, there is a performance bug here in that just doing the
> `C-h o PREF TAB` which completes to `PREFIX-` already loads `PREFIX.el`
> which is a bit over-enthusiatic (I intended it to load `PREFIX.el`
> only when you hit TAB while you already have `PREFIX-` in your
> minibuffer).

The patch below seems to fix this performance bug in my test.
Can you see if it avoids the major slowdown you're experiencing?

        Stefan
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index e1daa8977f0..a9634745282 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -206,9 +206,12 @@ help--symbol-completion-table
         ,@(when completions-detailed
             '((affixation-function . help--symbol-completion-table-affixation)))
         (category . symbol-help))
-    (when help-enable-completion-autoload
+    (when (and help-enable-completion-autoload
+               (memq action '(nil t lambda)))
       (let ((prefixes (radix-tree-prefixes (help-definition-prefixes) string)))
-        (help--load-prefixes prefixes)))
+        ;; Don't load FOO.el during `test-completion' of `FOO-'.
+        (unless (and (eq action 'lambda) (assoc string prefixes))
+          (help--load-prefixes prefixes))))
     (let ((prefix-completions
            (and help-enable-completion-autoload
                 (mapcar #'intern (all-completions string definition-prefixes)))))