all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Dmitrii Korobeinikov <dim1212k@gmail.com>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: Garbage collector: is 800kb a good default?
Date: Thu, 09 Apr 2020 09:47:38 -0400	[thread overview]
Message-ID: <jwvh7xs4wtt.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CA+Yh0SSmhbkJdz-M85WU9eFAgze1oicW8cGqEuqerd9KzC7NEw@mail.gmail.com> (Dmitrii Korobeinikov's message of "Thu, 9 Apr 2020 17:59:04 +0600")

> Of course, raising the threshold significantly higher on its own is
> not a very good idea. But if paired with an idle timer like suggested
> here [2], then it all starts looking like a decent combination:

I agree that it's worth investigating improvements based on dynamically
changing the GC threshold.  What you're pointing out is that from the
user's point of view, a GC during idle time is free (so it can occur
frequently) and also that a GC during non-idle time can delay redisplay,
so (ignoring all other impacts of GC) we should refrain from running GC
while non-idle and trigger GC everything we're idle.

Running GC frequently is done largely to try and keep total heap size
and memory fragmentation under control.  So completely refraining from
running GC while non-idle is probably not a great solution, but I do
agree that adding a "GC when idle" would not only be great in itself but
would also let us increase the default thresholds somewhat.  Tho I don't
think we can increase the threshold as much as you suggest without
having significant detrimental effects.

There 2 additional ways to attack the problem, BTW:

1- replace our GC with a concurrent GC.  This would let us move those
   38% GC overheard to one of the other CPU cores sitting idle while the
   only CPU core running Emacs is frantically trying to scroll through
   your buffer (it would also slow down both the GC and the main thread
   a bit, but in the current context of plentiful CPU cores it would
   still be very worthwhile).
   [ Along the same lines, making our GC parallel could cut those 38%
     down to some extent, as would a generational GC.  ]

2- 38% is pretty high.  Usually this indicates that the GC is not
   efficient: it works hard yet reclaims very little memory likely
   because the application is allocating a lot of objects which are
   *not* temporary.  This is also the typical situation during Emacs's
   startup where we're loading packages and initializing big
   data-structures, so after allocating our GC-threshold of data the GC
   is run but doesn't collect much garbage because all that data is
   there to stay.
   We can't really know beforehand if a GC will reclaim a lot of memory,
   but we could "use the past to predict the future": we could set the
   threshold higher when the last GC reclaimed too little garbage.

I had sent a tentative patch for the "GC when idle" feature but it had
some rough edges, and some details of the GC code have changed since.
I'd welcome a patch to do that.  It shouldn't require many changes.
Similarly, point (2) above should be fairly simple to add.


        Stefan




  parent reply	other threads:[~2020-04-09 13:47 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-09 11:59 Garbage collector: is 800kb a good default? Dmitrii Korobeinikov
2020-04-09 12:33 ` Eli Zaretskii
2020-04-09 13:44   ` Dmitrii Korobeinikov
2020-04-09 14:02     ` Eli Zaretskii
2020-04-09 14:46       ` Dmitrii Korobeinikov
2020-04-09 16:42         ` Eli Zaretskii
2020-04-10 16:40           ` Dmitrii Korobeinikov
2020-04-09 19:05         ` Stefan Monnier
2020-04-10 16:26           ` Dmitrii Korobeinikov
2020-04-09 18:48     ` Stefan Monnier
2020-04-10 14:26   ` Bruno Félix Rezende Ribeiro
2020-04-10 16:49     ` Eli Zaretskii
2020-04-10 18:26       ` Bruno Félix Rezende Ribeiro
2020-04-10 18:53         ` Paul Eggert
2020-04-09 13:47 ` Stefan Monnier [this message]
2020-04-09 14:20   ` Dmitrii Korobeinikov
2020-04-09 14:23   ` Eli Zaretskii
2020-04-09 18:42     ` Stefan Monnier
2020-04-09 19:08       ` Eli Zaretskii
2020-04-09 19:31         ` Stefan Monnier
2020-04-10  6:19           ` Eli Zaretskii
2020-04-10 13:03             ` Stefan Monnier
2020-04-10 13:42               ` Eli Zaretskii
2020-04-10 14:34                 ` Stefan Monnier
2020-04-10 14:38                   ` Stefan Monnier
2020-04-10 15:37                   ` Eli Zaretskii
2020-04-10 15:52                   ` Andrea Corallo
2020-04-10 16:45                     ` Stefan Monnier
2020-04-10 17:18                       ` Andrea Corallo
2020-04-09 14:48   ` Andrea Corallo

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=jwvh7xs4wtt.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=dim1212k@gmail.com \
    --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.