Subject: Re: bug#79021: 31.0.50; Unnecessary GC in after-load-functions

From: Daniel Colascione <[email-masked]>
Date: Fri, 12 Sep 2025 01:01:52 -0700

On September 12, 2025 12:54:42 AM PDT, Eli Zaretskii <[email-masked]> wrote:
>> From: Helmut Eller <[email-masked]>
>> Cc: Eli Zaretskii <[email-masked]>,  [email-masked]
>> Date: Fri, 12 Sep 2025 09:26:02 +0200
>> 
>> On Tue, Jul 15 2025, Stefan Monnier wrote:
>> 
>> >>> In loadup.el there is this:
>> >>> 
>> >>>   (add-hook 'after-load-functions (lambda (_) (garbage-collect)))
>> >>> 
>> >>> What's this for?  It seems unnecessary.
>> >>> 
>> >>> It would be nice to remove this, because without it the time to execute
>> >>> loadup.el goes down from 13 seconds to 6.
>> >>
>> >> I presume this is because we don't want to dump any garbage.
>> >> Stefan?
>> >
>> > AFAIK it was added to keep the dumped Emacs' heap "dense": if we run the
>> > GC only "in the normal way", the heap objects created during `loadup.el`
>> > end up interspersed with more free spaces.
>> >
>> > It's possible/likely that the portable dumper has made that unnecessary.
>> 
>> diff --git a/lisp/loadup.el b/lisp/loadup.el
>> index 18f09878f98..05bd468b713 100644
>> --- a/lisp/loadup.el
>> +++ b/lisp/loadup.el
>> @@ -127,7 +127,11 @@
>>  
>>  ;; Do it after subr, since both after-load-functions and add-hook are
>>  ;; implemented in subr.el.
>> -(add-hook 'after-load-functions (lambda (_) (garbage-collect)))
>> +;;
>> +;; This was probably done to reduce fragmentation with unexec.  With the
>> +;; pdumper it makes little sense.  See bug#79021.
>> +(if (not (fboundp 'dump-emacs-portable))
>> +    (add-hook 'after-load-functions (lambda (_) (garbage-collect))))
>
>Are we sure the problem no longer happens with pdumper?  Daniel, WDYT?
>

It's unnecessary with pdumper, which compacts automatically.

>In any case, the fboundp test is not enough, we should test the value
>of dump-mode instead, I think.  Because Emacs might be built with
>pdumper support, but this session is not going to call
>dump-emacs-portable, due to command-line options or some other trick.

Just delete it.