Subject: Re: bug#65250: 30.0.50; "C-h f" is much slower on the master branch

From: Andrea Corallo <[email-masked]>
Date: Mon, 14 Aug 2023 10:51:46 -0400

Eli Zaretskii <[email-masked]> writes:

>> Cc: [email-masked]
>> Date: Mon, 14 Aug 2023 15:19:16 +0300
>> From: Eli Zaretskii <[email-masked]>
>> 
>>    'configure -C --prefix=/d/usr --with-wide-int
>>    --enable-checking=yes,glyphs 'CFLAGS=-O0 -gdwarf-4 -g3''
>> 
>> Perhaps --enable-checking makes the difference?
>> 
>> If even that doesn't show the problem, just time the above and compare
>> with Emacs 29: it's possible that the command is much faster on your
>> system, but the question is it significantly slower than Emacs 29?
>
> It sounds like the problem is the packages that Emacs needs to load
> when comp-function-type-spec is called.  If I set force-load-messages
> to t before invoking "C-h f", I see this in the *Messages* buffer:
>
>   Loading help-fns...
>   Loading cl-lib...
>   Loading cl-loaddefs...done
>   Loading cl-lib...done
>   Loading help-mode...done
>   Loading radix-tree...done
>   Loading help-fns...done
>   Loading thingatpt...done
>   Loading dictionary...
>   Loading dictionary-connection...done
>   Loading external-completion...done
>   Loading dictionary...done
>   Loading lisp/emacs-lisp/comp.el (source)...
>   Loading bytecomp...done
>   Loading cl-extra...done
>   Loading cl-macs...
>   Loading gv...done
>   Loading cl-macs...done
>   Loading cl-seq...done
>   Loading rx...done
>   Loading subr-x...done
>   Loading warnings...
>   Loading icons...done
>   Loading warnings...done
>   Loading lisp/emacs-lisp/comp-cstr.el (source)...
>   Loading pcase...done
>   Loading lisp/emacs-lisp/comp-cstr.el (source)...done
>   Loading derived...done
>   Loading lisp/emacs-lisp/comp.el (source)...done
>   Loading shortdoc...
>   Loading text-property-search...done
>   Loading shortdoc...done
>
> Note the loading of comp.el and comp-cstr.el -- we load their source
> files, not the *.elc files.  That's because in a build without native
> compilation these two files are not byte-compiled.  I think loading of
> these files, especially of comp.el, in source form is what slows down
> the command.

Maybe, comp-cstr.el might have even a bigger part.

> I'm guessing your build was with native compilation?

Yes, I was experimenting just now (and failing to reproduce) with

CFLAGS='-O0 -gdwarf-4 -g3' ./configure --without-x
--with-native-compilation=yes --prefix='/home/andcor03'
--enable-checking=yes,glyphs --with-wide-int

> Because in such
> a build the "C-h f" command is indeed fast, especially after the
> requisite *.el files are all native-compiled (i.e. starting from the
> second Emacs invocation after the build).

Ah right! now it's all clear!

> So I think the patch I presented in my original report is exactly what
> is needed here: the problem only happens in builds without
> native-compilation, and in that case there's no reason whatsoever to
> call comp-function-type-spec.  (And builds from a release tarball will
> not see that problem, since the tarball comes with byte-compiled
> comp.el and comp-cstr.el.)
>
> Do you agree?

I certainly do.  Thanks for the anylysis and the patch!

  Andrea