[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A faster derived-mode-p
From: |
Lars Ingebrigtsen |
Subject: |
Re: A faster derived-mode-p |
Date: |
Mon, 15 Feb 2021 03:56:29 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> 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))
Hm, right... As Dmitry showed, my worries about the inefficiency of
derived-mode-p seem exaggerated, but if it turns out to be a problem (or
we have more complex predicates), then doing something like this seems
promising.
However, the vast, vast number of the predicates basically devolve to
this (on the happy path):
(or (derived-mode-p 'foo-mode)
(memq 'foo-mode minor-modes)
(memq 'foo-mode global-minor-modes))
The derived-mode-p is fast, `minor-modes' is typically less than four
elements, and the same with `global-minor-modes'. I'm not sure that
it's likely that looping over the symbols and entering the predicates
into a hash table has much scope for improving the speed much -- it'll
already be quite speedy.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no