GNU bug report logs - #65700
time when gcs-done is updated needs to be clarified

Previous Next

Package: emacs;

Reported by: Shynur Xie <one.last.kiss <at> outlook.com>

Date: Sat, 2 Sep 2023 13:03:02 UTC

Severity: wishlist

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


Message #22 received at 65700 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Shynur Xie <one.last.kiss <at> outlook.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>,
 "65700 <at> debbugs.gnu.org" <65700 <at> debbugs.gnu.org>
Subject: Re: bug#65700: time when gcs-done is updated needs to be clarified
Date: Thu, 07 Sep 2023 10:58:46 -0400
>> I'd be curious to know how it affects your code.
> My Emacs displays its runtime information like this:
>   <github.com/shynur/.emacs.d/issues/1#issuecomment-1671815270>
> Since it's mainly related to GC, I have it updated after each GC.

Hmm... that doesn't really explain in which way this affects your code.
If you only ever run that from `post-gc-hook` the only difference is
that `gcs-done` will be always smaller by 1 and since it doesn't start
at 0 anyway it's not really relevant: it will still increase by 1 every
time `post-gc-hook` is run.

FWIW, I tend to agree that it would be more useful to run `post-gc-hook`
after those values have been updated.  So that `post-gc-hook` can know
the exact duration of the GC that we just finished, rather than the one
before that.

Any objection to the patch below?


        Stefan


diff --git a/src/alloc.c b/src/alloc.c
index c77bdc6372d..cee43783387 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -6595,13 +6595,6 @@ garbage_collect (void)
   image_prune_animation_caches (false);
 #endif
 
-  if (!NILP (Vpost_gc_hook))
-    {
-      specpdl_ref gc_count = inhibit_garbage_collection ();
-      safe_run_hooks (Qpost_gc_hook);
-      unbind_to (gc_count, Qnil);
-    }
-
   /* Accumulate statistics.  */
   if (FLOATP (Vgc_elapsed))
     {
@@ -6620,6 +6613,13 @@ garbage_collect (void)
       if (tot_after < tot_before)
 	malloc_probe (min (tot_before - tot_after, SIZE_MAX));
     }
+
+  if (!NILP (Vpost_gc_hook))
+    {
+      specpdl_ref gc_count = inhibit_garbage_collection ();
+      safe_run_hooks (Qpost_gc_hook);
+      unbind_to (gc_count, Qnil);
+    }
 }
 
 DEFUN ("garbage-collect", Fgarbage_collect, Sgarbage_collect, 0, 0, "",





This bug report was last modified 1 year and 283 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.