Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

startup: Print GC information #138

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

startup: Print GC information #138

wants to merge 4 commits into from

Conversation

rye
Copy link
Member

@rye rye commented Jul 24, 2020

Because we (currently) use an interesting hodgepodge of sync and async loading during startup, I think it might be useful to convey to the user some information about how much garbage collection occurred during startup. Loading things (processing functions, strings, etc., and just general startup work) will necessarily produce garbage to be swept, and so it might be helpful to know just how much is happening during our init sweep.

This PR adds a small printout of the number of GC sweeps and the amount of time spent doing GC during startup. The initial-scratch-message is populated by the after-init-hook which means the readout should capture all the GC data.

;; init: 3.6 seconds @ 2020-07-24 12:47:05 (gc: 42x, 0.900s)
;; [email protected] loaded config for rye
;; need help? try <C-h ?>
;; scratch away

I've had success in reducing the number of GCs by bumping up gc-cons-threshold and fiddling with gc-cons-percentage, but it's nice to be able to get a grasp on where we're at right now.

One possible change I could make is to gate this behind a variable. Note that both gcs-done and gc-elapsed are variables that are populated by Emacs' C code in alloc.c, so this doesn't add much overhead besides a few more strings in the concat call and the two calls to format.

rye added 4 commits July 24, 2020 12:11
Now, we can get some idea for what is happening when Emacs is starting
up.  Here we don't actually print any information about the *time* spent
in GC, but we do get an idea for the number of GCs done.

The Emacs garbage collector operates by finding and "marking" all Lisp
objects that are still accessible to Lisp programs.  It assumes that all
symbols and their associated values and function definitions, and things
present on the stack are accessible.  Then any objects reachable through
these presumed-accessible objects are also considered accessible.  After
the process of markinging accessible Lisp objects is done, those left
unmarked are garbage, and cannot be reached by normal means.

It can be quite helpful to know how many GC operationss were performed
during startup to see if the GC parameters are set properly.  On my
system, for example, the gc-cons-threshold is merely 800_000 bytes (800
KB).  This is the default for 64-bit systems, but results in 42 GC
sweeps being performed during startup, which take a non-trivial amount
of time.

Signed-off-by: Kristofer Rye <[email protected]>
I think this is probably very useful for us to have in addition to the
gcs-done printout.

Signed-off-by: Kristofer Rye <[email protected]>
This makes it fit better on the screen, while still conveying the same
amount of information.

Signed-off-by: Kristofer Rye <[email protected]>
We don't really need to know how much time is spent in GC down to the
microsecond.  Milliseconds (10^{-3}s) should be plenty of precision, as
the user can always go and inspect gc-elapsed as they please.

Signed-off-by: Kristofer Rye <[email protected]>
@rye rye self-assigned this Jul 24, 2020
@rye rye requested review from cg505 and samontea July 24, 2020 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant