all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Eager garbage collection
@ 2020-11-16  4:11 sbaugh
  2020-11-16 15:07 ` Stefan Monnier
  0 siblings, 1 reply; 44+ messages in thread
From: sbaugh @ 2020-11-16  4:11 UTC (permalink / raw)
  To: emacs-devel


Inspired by http://akrl.sdf.org/ and an earlier patch from Stefan
Monnier, I've written the below patch.  Previously, on no user input, we
called maybe_gc, which doesn't do much.  This patch turns that call into
an eager garbage collection attempt.

Ideally, this will reduce the rate of garbage collections happening in
the middle of user operations.

I've tested this a bit and, at least, it seems to successfully trigger
eager garbage collections when there is no user input.

Does this kind of change seem plausible?

diff --git a/src/alloc.c b/src/alloc.c
index 2b3643e35b..33f0a8ab3b 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -5961,6 +5961,16 @@ maybe_garbage_collect (void)
     garbage_collect ();
 }
 
+/* Like maybe_garbage_collect, but with the GC threshold halved as a
+   way to GC eagerly.  The GC threshold will be reset on our next call
+   to maybe_garbage_collect. */
+void
+maybe_garbage_collect_eagerly (void)
+{
+  if (bump_consing_until_gc (gc_cons_threshold/2, Vgc_cons_percentage) < 0)
+    garbage_collect ();
+}
+
 /* Subroutine of Fgarbage_collect that does most of the work.  */
 void
 garbage_collect (void)
diff --git a/src/keyboard.c b/src/keyboard.c
index 49a0a8bd23..da384e9b45 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -2752,7 +2752,7 @@ read_char (int commandflag, Lisp_Object map,
 
       /* If there is still no input available, ask for GC.  */
       if (!detect_input_pending_run_timers (0))
-	maybe_gc ();
+	maybe_garbage_collect_eagerly ();
     }
 
   /* Notify the caller if an autosave hook, or a timer, sentinel or
diff --git a/src/lisp.h b/src/lisp.h
index 76d74200ac..8778a07fbb 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3793,6 +3793,7 @@ flush_stack_call_func (void (*func) (void *arg), void *arg)
 
 extern void garbage_collect (void);
 extern void maybe_garbage_collect (void);
+extern void maybe_garbage_collect_eagerly (void);
 extern const char *pending_malloc_warning;
 extern Lisp_Object zero_vector;
 extern EMACS_INT consing_until_gc;




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

end of thread, other threads:[~2020-12-05 14:41 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <Message-ID: <jwv1rgtjhhy.fsf-monnier+emacs@gnu.org>
2020-11-18  0:20 ` Eager garbage collection Spencer Baugh
2020-11-18  0:20   ` [PATCH 1/3] Add gc-estimated-time variable Spencer Baugh
2020-11-18 17:45     ` Eli Zaretskii
2020-11-18  0:20   ` [PATCH 2/3] Add garbage-collect-maybe function Spencer Baugh
2020-11-18 17:49     ` Eli Zaretskii
2020-11-18  0:20   ` [PATCH 3/3] Start opportunistic GC timer at startup Spencer Baugh
2020-11-18 17:54     ` Eli Zaretskii
2020-11-18  3:45   ` Eager garbage collection Stefan Monnier
2020-11-18  4:05     ` Spencer Baugh
2020-11-18  4:48       ` Stefan Monnier
2020-11-18  8:02   ` Andrea Corallo via Emacs development discussions.
2020-11-18 15:06     ` Eli Zaretskii
2020-11-18 15:30       ` Andrea Corallo via Emacs development discussions.
2020-11-18 17:19         ` Eli Zaretskii
2020-11-18 17:26           ` Andrea Corallo via Emacs development discussions.
2020-11-18 18:07             ` Eli Zaretskii
2020-11-18 18:19               ` Andrea Corallo via Emacs development discussions.
2020-11-18 15:19     ` Spencer Baugh
2020-11-18 15:47       ` Andrea Corallo via Emacs development discussions.
2020-11-18 16:52         ` Stefan Monnier
2020-11-18 17:12           ` Andrea Corallo via Emacs development discussions.
2020-11-18 17:34           ` Eli Zaretskii
2020-11-18 18:00   ` Eli Zaretskii
2020-11-22  5:07     ` Spencer Baugh
2020-11-22  5:08       ` [PATCH v2 1/3] Add gc-estimated-time variable Spencer Baugh
2020-11-22 18:10         ` Eli Zaretskii
2020-11-22 19:48           ` Stefan Monnier
2020-11-22  5:08       ` [PATCH v2 2/3] Add garbage-collect-maybe function Spencer Baugh
2020-11-22 18:14         ` Eli Zaretskii
2020-11-22  5:08       ` [PATCH v2 3/3] Start opportunistic GC timer at startup Spencer Baugh
2020-12-04 23:19         ` Stefan Monnier
2020-12-05  7:52           ` Eli Zaretskii
2020-12-05 13:55             ` Stefan Monnier
2020-12-05 14:24               ` Eli Zaretskii
2020-12-05 14:41                 ` Stefan Monnier
2020-11-22 15:13       ` Eager garbage collection Eli Zaretskii
2020-11-16  4:11 sbaugh
2020-11-16 15:07 ` Stefan Monnier
2020-11-16 16:34   ` Eli Zaretskii
2020-11-16 18:37     ` Stefan Monnier
2020-11-18 18:00     ` yyoncho
2020-11-18 18:16       ` Eli Zaretskii
2020-11-18 21:37         ` Stefan Monnier
2020-11-18 21:59           ` Stefan Monnier

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.