Subject: bug#63132: Bug on Darwin MacOS with 'M-x man RET commandname[ ]'

From: Eshel Yaron <[email-masked]>
Date: Wed, 03 May 2023 15:09:09 +0300

Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <[email-masked]> writes:

>> On my i9 Ventura MacBook Pro, just running `man -k read > /dev/null`
>> takes almost 2.5 seconds, it'd seem that's indeed the main cause of this
>> lag in `M-x man` completion.
>
> Hmm... here on my 10 years old desktop running Debian stable it's more
> like 0.03s.  If it's so slow even for situations where the users have
> already typed `read`, ... hmm ... maybe we should try and make the
> completion asynchronous or at least abort the `man -k` as soon as the
> user types something, or add some level of caching...?
>

Note that there is already some caching in place, but it gets reset
between invocations of `M-x man` and it only hits if the previous input
for completion is a prefix of the next one.

AFAICT Stefan added this caching back in 2009 along with a comment that
seems to be relevant still:

--8<---------------cut here---------------start------------->8---
On my machine, "man -k" is so fast that a cache makes no sense,
but apparently that's not the case in all cases, so let's add a cache.
--8<---------------cut here---------------end--------------->8---

Perhaps we could do some more aggressive caching under the condition
that "man -k" is really slow (as determined by e.g. some
`Man-man-k-slow-p` variable that'd be non-nil by default on macOS)?

-- 
Eshel