emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A faster derived-mode-p


From: Stefan Monnier
Subject: Re: A faster derived-mode-p
Date: Sun, 14 Feb 2021 18:51:04 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> There are only 11K commands in the Emacs tree, so I don't know whether
> the current default completion predicate is going to turn out to be
> problematically slow or not.

Here's my suggestion:
Instead of trying to speed up those 10K predicates we're going to have
to evaluate, we could try to take advantage of the fact that there
should be a lot of redundancy there.

So we could do something like:

    (let ((cmds (make-hash-table :test #'equal)))
      (mapatom (lambda (sym)
                 (when (commandp sym)
                   (push sym (gethash (command-predicate sym) cmds)))))
      (let (active-cmds)
        (maphash (lambda (pred syms)
                   (when (funcall pred)
                     (cl-callf nconc active-cmds syms)))
                 cmds)
        active-cmds))

The only problem I can foresee here is that we have no guarantee that

    (equal (lambda () (derived-mode-p 'foo-mode))
           (lambda () (derived-mode-p 'foo-mode)))

To reduce the risk of such problems we could change the "predicate"
from being a function that takes 0 arguments, to being a list
a list (FUN . ARGS), so instead of

    (funcall pred)

we'd have to do:

    (apply pred)

So instead of

    (lambda () (derived-mode-p 'foo-mode))

the internal representation of the "predicate" would be

    (derived-mode-p foo-mode)

it should also make equality testing (within `gethash`) faster.

Of course, if we can arrange for the command predicates to be written
(in the source file) a single time for groups of commands (which would
also be beneficial to reduce the amount of redundancy in the source code
and the amount of work needed by authors), then we could even use `eq`
comparisons and still get most of the benefit.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]