all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: emacs-devel@gnu.org
Subject: Re: A faster derived-mode-p
Date: Sun, 14 Feb 2021 18:51:04 -0500	[thread overview]
Message-ID: <jwvblcm43ws.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87k0ra9z7w.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sun, 14 Feb 2021 21:22:11 +0100")

> 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




  parent reply	other threads:[~2021-02-14 23:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-14 20:22 A faster derived-mode-p Lars Ingebrigtsen
2021-02-14 22:25 ` Dmitry Gutov
2021-02-14 22:45   ` Basil L. Contovounesios
2021-02-14 23:03     ` Óscar Fuentes
2021-02-15  2:34     ` Dmitry Gutov
2021-02-15  2:47       ` Lars Ingebrigtsen
2021-02-14 23:51 ` Stefan Monnier [this message]
2021-02-15  2:56   ` Lars Ingebrigtsen

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

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

  git send-email \
    --in-reply-to=jwvblcm43ws.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.