Subject: Re: bug#79074: 31.0.50; Increase gc-cons-percentage in Makefiles

From: Helmut Eller <[email-masked]>
Date: Wed, 23 Jul 2025 14:03:44 +0200

On Tue, Jul 22 2025, Eli Zaretskii wrote:

[...]
>> So I think we should add something to BYTE_COMPILE_FLAGS to increase
>> gc-cons-percentage; or perhaps increase it in batch-byte-compile.
>
> We could certainly try that; patches welcome.

Here is a one:

>From 1302cc2e175452b2a6c9c7d200e8a34149025ac0 Mon Sep 17 00:00:00 2001
From: Helmut Eller <[email-masked]>
Date: Wed, 23 Jul 2025 13:34:32 +0200
Subject: [PATCH] Increase gc-cons-percentage when building .elc files

* lisp/Makefile.in (BYTE_COMPILE_GC_FLAGS): New.
(BYTE_COMPILE_FLAGS): Use it.
---
 lisp/Makefile.in | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/Makefile.in b/lisp/Makefile.in
index 17182357739..7cfafe81280 100644
--- a/lisp/Makefile.in
+++ b/lisp/Makefile.in
@@ -71,13 +71,19 @@ loaddefs =
 AUTOGENEL = ${loaddefs} ${srcdir}/cus-load.el ${srcdir}/finder-inf.el \
   ${srcdir}/subdirs.el ${srcdir}/eshell/esh-groups.el
 
+# Increasing gc-cons-percentage uses more memory but reduces compilation
+# times.
+BYTE_COMPILE_GC_FLAGS = --eval '(setq gc-cons-percentage 1.2)'
+
 # Set load-prefer-newer for the benefit of the non-bootstrappers.
 # Set org--inhibit-version-check to avoid unnecessarily aborting the build.
 BYTE_COMPILE_FLAGS = \
+  $(BYTE_COMPILE_GC_FLAGS) \
   --eval "(setq load-prefer-newer t byte-compile-warnings 'all)" \
   --eval "(setq org--inhibit-version-check t)" $(BYTE_COMPILE_EXTRA_FLAGS)
 # ... but we must prefer .elc files for those in the early bootstrap.
-compile-first: BYTE_COMPILE_FLAGS = $(BYTE_COMPILE_EXTRA_FLAGS)
+compile-first: BYTE_COMPILE_FLAGS = \
+  $(BYTE_COMPILE_GC_FLAGS) $(BYTE_COMPILE_EXTRA_FLAGS)
 
 # Files to compile before others during a bootstrap.  This is done to
 # speed up the bootstrap process.  They're ordered by size, so we use
-- 
2.39.5

> P.S. The above benchmark should be repeated with native-compilation,
> IMO.

I repeated it for "make bootstrap" because I don't know how to only
rebuild the lisp directory with native-compilation.

So basically I did:

for percentage in 0.1 0.75 1.5 ; do
    /usr/bin/time -o make-$percentage.time make -l3.2 -j4 \
 BYTE_COMPILE_EXTRA_FLAGS="--eval '(setq gc-cons-percentage $percentage)'" \
 FAST=true -l3.2 -j4 bootstrap
done

The results are:

* for gc-cons-percentage = 0.1:
2331.71user 86.23system 14:38.08elapsed 275%CPU (0avgtext+0avgdata 641880maxresident)k
4432inputs+742056outputs (18major+14952231minor)pagefaults 0swaps

* for gc-cons-percentage = 0.75:
1223.32user 85.96system 8:06.30elapsed 269%CPU (0avgtext+0avgdata 706240maxresident)k
0inputs+742064outputs (2major+15873839minor)pagefaults 0swaps

* for gc-cons-percentage = 1.5:
961.91user 94.57system 6:32.58elapsed 269%CPU (0avgtext+0avgdata 766348maxresident)k
16inputs+742064outputs (0major+18617902minor)pagefaults 0swaps

[BTW, boostrapping the igc branch requires:
1039.27user 181.75system 7:19.31elapsed 277%CPU (0avgtext+0avgdata 929092maxresident)k
38960inputs+682528outputs (8major+27973694minor)pagefaults 0swaps ]

For fun, I also recorded the times for individual compilation processes.
Here a scatter plot of the result:

Some statistics:

 gc-cons-percentage │ variable  mean       min      median   max    
────────────────────┼───────────────────────────────────────────────
                0.1 │ real      1.3452     0.12     0.48     162.52 
                0.1 │ rssmax    51622.8    42692    45388.0  641880 
		    │
               0.75 │ real      0.660551   0.1      0.285    69.69  
               0.75 │ rssmax    54213.1    43032    47932.0  706240 
	            │
                1.5 │ real      0.507625   0.08     0.22     62.93  
                1.5 │ rssmax    60135.5    43060    55508.0  766348 

and here the full tables, if somebody is interested: