all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: Increase gc-cons-threshold during package-init?
Date: Mon, 19 Feb 2018 16:15:44 -0500	[thread overview]
Message-ID: <jwvh8qc7l1i.fsf-monnier+gmane.emacs.devel@gnu.org> (raw)
In-Reply-To: p914lmchp0s.fsf@google.com

> With Emacs now calling package-initialize on its own,

Not sure what you mean by "now": it's been the case since Emacs-24.1
(recent changes on `master` have only moved the time at which it takes
place).

> that emacs startup was now  entailing 3 times as many gc calls during
> startup as before.  One guess is that my init file was lexically
> binding gc-cons-threshold to 64MB ---

Lexically-binding it would have no effect on the GC, and since that var
is declared as dynamically scoped, it was probably dynamically bound.

Have you checked how much extra time is spent in the GC because of those
extra calls?

> the default gc-cons-threshold of 800K is likely from the past and
> could be increased.

This is a misunderstanding: the real gc-cons-threshold is computed
dynamically based on the heap size (see gc-cons-percentage).

Maybe those values need to be tweaked because tradeoffs have shifted
somewhat, but it doesn't seem very likely.

The problem with the above GC calls is much more fundamental and
unrelated to the actual values we choose: during periods of
initialization, programs typically allocate a lot of memory without
generating much garbage.  So during those times running a GC tends to be
a waste of effort (we scan the whole heap only to find a few crumbs here
and there).

People often look at situations like yours and conclude that
gc-cons-threshold is too small.  Yes, it's too small for those cases,
but bumping it once and forall makes things worse for the "usual" case,
leading to increased heap size, fragmentation, and longer pauses during
normal operation (tho this "usual case" is much more difficult to
measure).

There's no sadly way the GC can magically know that the last N megabytes
of allocation generated very little garbage, tho.

Maybe should bump those gc-knobs around the startup.el code (or maybe
more generally we should bump those knobs while loading a file).

> Even if we leave the default as is, it might make sense to temporarily
> increase gc-cons-threshold within package-initialize

Right.  Tho doing this will likely cause a GC to happen right after
package-initialize, i.e. just before loading your ~/.emacs.
Better would be to bump it around both, I guess.


        Stefan




  parent reply	other threads:[~2018-02-19 21:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-19 17:23 Increase gc-cons-threshold during package-init? T.V Raman
2018-02-19 17:27 ` Daniel Colascione
2018-02-19 18:35   ` Eli Zaretskii
2018-02-19 21:15 ` Stefan Monnier [this message]
2018-02-20  0:49   ` T.V Raman
2018-02-20 17:27 ` Radon Rosborough

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvh8qc7l1i.fsf-monnier+gmane.emacs.devel@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.