From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Shynur Xie <one.last.kiss@outlook.com>, 65700@debbugs.gnu.org
Subject: bug#65700: time when gcs-done is updated needs to be clarified
Date: Thu, 07 Sep 2023 09:38:35 -0400 [thread overview]
Message-ID: <jwvtts6f705.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <83pm2uz6nv.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 07 Sep 2023 12:14:44 +0300")
>> I wrote a function which runs each time Emacs collects garbage, so I
>> added it to `post-gc-hook'.
>>
>> That function cares about the value of `gcs-done' and the value of
>> `gc-elapsed'. But it seems that `gcs-done' is updated after
>> `post-gc-hook' is executed?
Indeed, from what I see in the code, `gc-elapsed` and `gcs-done` are
updated *after* running `post-gc-hook`.
This means for example that the time to run `post-gc-hook` is included
in the `gc-elapsed` time.
>> Is this an intended behavior?
Good question. AFAICT this was added by the following commit:
commit 2c5bd60800ce4f2702f263eda2145be342208ffe
Author: Dave Love <fx@gnu.org>
Date: Thu Jan 30 14:15:58 2003 +0000
(Vgc_elapsed, gcs_done): New variables.
(Fgarbage_collect): Use them.
(init_alloc, syms_of_alloc): Set them up.
diff --git a/src/alloc.c b/src/alloc.c
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -4367,7 +4373,15 @@
if (!NILP (Vpost_gc_hook))
{
int count = inhibit_garbage_collection ();
safe_run_hooks (Qpost_gc_hook);
unbind_to (count, Qnil);
}
-
+
+ /* Accumulate statistics. */
+ EMACS_GET_TIME (t2);
+ EMACS_SUB_TIME (t3, t2, t1);
+ if (FLOATP (Vgc_elapsed))
+ XSETFLOAT (Vgc_elapsed, make_float (XFLOAT_DATA (Vgc_elapsed) +
+ EMACS_SECS (t3) +
+ EMACS_USECS (t3) * 1.0e-6));
+ gcs_done++;
The only related commit I see around that time is the associated NEWS
message:
** New variables `gc-elapsed' and `gcs-done' provide extra information
on garbage collection.
So I strongly suspect that it was largely accidental. "Philosophically",
both choices make sense (either consider `post-gc-hook` as being part of
the GC or consider it as external to the GC).
I'd be curious to know how it affects your code.
Stefan
next prev parent reply other threads:[~2023-09-07 13:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-02 13:00 bug#65700: time when gcs-done is updated needs to be clarified Shynur Xie
2023-09-07 9:14 ` Eli Zaretskii
2023-09-07 13:38 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-09-07 14:35 ` Shynur Xie
2023-09-07 14:47 ` Eli Zaretskii
2023-09-07 15:23 ` Shynur Xie
2023-09-07 16:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-07 17:19 ` Shynur Xie
2023-09-12 10:14 ` Shynur Xie
2023-09-12 12:53 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-12 18:07 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-07 14:58 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-07 15:08 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvtts6f705.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=65700@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=one.last.kiss@outlook.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).