doomemacs/lisp
Henrik Lissner 46e23f37ba
fix: memory leak & freezes on native-comp+pgtk builds
b7f84bd introduced a nasty regression that caused an infinite loop and
runaway memory usage on some pgtk+native-comp builds of Emacs when it
attempted to perform deferred native compilation of your packages. This
would make Emacs unusable and, if left alone, could even crash your
system.

The only Emacs builds I'm certain are affected are derived from
flatwhatson/emacs (like emacs-pgtk-native-comp on Guix and Arch Linux in
particular). 28.1 stable and master (on emacs-mirror/emacs@e13509468b)
are unaffected.

It appears that some, earlier pgtk builds stack idle timers differently.
I'm not entirely sure how, because it doesn't manifest in more recent
builds of Emacs, and I'm already burnt out on debugging this, but here's
how Doom encountered it:

Doom has an incremental package loader; it loads packages, piecemeal,
after Emacs has been idle for 2s, then again every 0.75s until it
finishes or the user sends input (then it waits another 2s before
starting again). However, if at any time the iloader detected that
native-compilation is in progress, it waits 2s before trying
again (repeat, until native-comp is done). But here's the catch, given
the following:

  (run-with-idle-timer
   2 nil (lambda ()
           (run-with-idle-timer 1 nil (lambda () (message "hi")))))

I had assumed "hi" would be emitted after 3 seconds (once idle), but
instead it is emitted after 2. Like this, Doom's iloader would elapse
one idle timer directly into another, ad infinitum, until Emacs was
forcibly killed.

By switching to run-at-time and employing my own rudimentary idle timer,
I avoid this issue. Also, the iloader no longer needs to be considerate
of native-comp, because the latter does its own rate-limiting controlled
by native-comp-async-jobs-number.

Amend: b7f84bdd01
2022-09-10 01:38:58 +02:00
..
cli fix(cli): wrong-number-of-args error when auto-resolving prompts 2022-09-10 01:36:58 +02:00
lib refactor(lib): use num-processors 2022-09-08 13:36:17 +02:00
doom-cli.el refactor(lib): provide doom-libs as subfeatures 2022-09-08 00:20:26 +02:00
doom-editor.el refactor: deprecate doom-etc-dir for doom-data-dir 2022-08-14 20:43:35 +02:00
doom-keybinds.el refactor: deprecate featurep! for modulep! 2022-08-14 20:43:35 +02:00
doom-lib.el feat(lib): add doom-{require,load} 2022-09-07 23:19:37 +02:00
doom-modules.el fix: remove use-package-font-lock-keywords reference 2022-09-06 22:55:46 +02:00
doom-packages.el tweak: disable ahead-of-time native compilation 2022-09-06 22:55:47 +02:00
doom-projects.el fix: validate fd --version output 2022-09-07 01:48:37 +02:00
doom-start.el fix: memory leak & freezes on native-comp+pgtk builds 2022-09-10 01:38:58 +02:00
doom-ui.el refactor: deprecate doom-private-dir for doom-user-dir 2022-08-14 20:43:35 +02:00
doom.el fix: memory leak & freezes on native-comp+pgtk builds 2022-09-10 01:38:58 +02:00
packages.el bump: :core 2022-09-06 22:55:47 +02:00