Subject: Re: bug#79346: igc: PolicyShouldCollectWorld

From: Gerd Möllmann <[email-masked]>
Date: Thu, 04 Sep 2025 05:14:49 +0200

Eli Zaretskii <[email-masked]> writes:

>> From: Helmut Eller <[email-masked]>
>> Date: Sun, 31 Aug 2025 11:21:41 +0200
>> 
>> On Sun, Aug 31 2025, Eli Zaretskii wrote:
>> 
>> >> It looks like the bug is in ArenaStep: it should divide the by
>> >> clocks_per_second before calling PolicyShouldCollectWorld.
>> >
>> > What does this affect in Emacs?
>> 
>> This affects how often MPS begins opportunistic GC, i.e. it affects only
>> sessions where igc-step-interval > 0.
>> 
>> Because of the bug, full collections are started more frequently because
>> availableTime > collectionTime is true more often. (availableTime is
>> 10^6 times bigger than it should be.)
>> 
>> The documentation of PolicyShouldCollectWorld says that it starts a full
>> collection only if it expects that the full collection can be completed
>> within availableTime (= igc-step-interval) and if enough time (= per
>> process time) has passed since the last full collection.
>> 
>> > And is this relevant to using a non-debug build of the library?
>> 
>> Yes.
>
> OK, thanks.  I guess it will be interesting to see what happens if
> people use a patched MPS with this bug fixed.

Good find, Helmut. There used to be a comment in arena_step wondering
what's going on, but it got removed, apparently. Does this look right?

>From 061b20ded1a35c674ad77b5afc7e68e753da1a3d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= <[email-masked]>
Date: Thu, 4 Sep 2025 04:50:26 +0200
Subject: [PATCH] Fix bug calculating available time in ArenaStep

* code/global.c (ArenaStep): Divide time by clocks_per_sec.
---
 code/global.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/code/global.c b/code/global.c
index 6c7cd39b9..6595fb6df 100644
--- a/code/global.c
+++ b/code/global.c
@@ -789,7 +789,7 @@ Bool ArenaStep(Globals globals, double interval, double multiplier)
       trace = ArenaTrace(arena, (TraceId)0);
     } else {
       /* No traces are running: consider collecting the world. */
-      if (PolicyShouldCollectWorld(arena, (double)(availableEnd - now), now,
+      if (PolicyShouldCollectWorld(arena, (double)(availableEnd - now)/clocks_per_sec, now,
                                    clocks_per_sec))
       {
         Res res;
-- 
2.51.0