unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Garbage collector: is 800kb a good default?
@ 2020-04-09 11:59 Dmitrii Korobeinikov
  2020-04-09 12:33 ` Eli Zaretskii
  2020-04-09 13:47 ` Stefan Monnier
  0 siblings, 2 replies; 30+ messages in thread
From: Dmitrii Korobeinikov @ 2020-04-09 11:59 UTC (permalink / raw)
  To: emacs-devel

Hi all,

So, I was debugging scrolling, it felt evidently clunky for large
files for me. Font lock is the elephant in the room, but I decided to
profile my custom half-screen scroll functions anyway and was quite
surprised to find that GC was gobbling 38% of the CPU time. That
didn't have anything to do with my functions, the default full page
scroll has it the same.

That lead to some experimenation with gc-cons-threshold. Higher values
of this variable resulted in much less frequent freezes/pauses while
scrolling [1]. Setting garbage-collection-messages to t and
gs-cons-threshold to 80MB, I figured I can scroll a voluminous sheet
of 7k lines before gc has to do its job. With the default 0.8 it's
every 2-3 pagescrolls. That's a big difference.

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:

(setq gc-cons-threshold mem)
(run-with-idle-timer 2 t 'garbage-collect)

It would be good to find a threshold which the user barely has a
chance of reaching unless running a long uninterrupted task. And, by
the way, in this latter case, it is better to have a higher threshold
too due to the increase in speed, like with startup [3]. Setting the
threshold just a bit higher than the current default wouldn't help
much but may actually be worse as the pauses would be longer, but
about as frequent. Too high a value would create very long freezes for
uninterrupted tasks. But there should be a good middle ground.

So, as far as I can see, defaulting to a higher threshold with an idle
timer could yield better user experience with practically no
significant tradeoffs. Is there something I might be missing here?

Best,
DK

[1] This is evident in vanilla emacs if you pay attention, but it's
much more so for me w/ my the bloated config. I haven't yet found the
culprit.
[2] https://emacs.stackexchange.com/questions/34342/is-there-any-downside-to-setting-gc-cons-threshold-very-high-and-collecting-ga
[3]
| threshold (MB) | startup time (s) |
|----------------+------------------|
|            0.8 |             9.14 |
|              2 |             8.77 |
|              5 |             7.54 |
|             20 |             6.88 |
|             50 |             6.65 |
|             80 |             6.73 |
|            100 |             6.17 |



^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2020-04-10 18:53 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).