This patch disables the final GC for finalizer forcing at normal program 
termination
if no finalizers are live as the GC is unnecessary in such cases.

felix

From fe21a1e2d61196d07f766fac87d8bf54dcc95336 Mon Sep 17 00:00:00 2001
From: felix <fe...@call-with-current-continuation.org>
Date: Tue, 7 Apr 2020 12:40:22 +0200
Subject: [PATCH] Only force finalizers at program cleanup when live finalizer
 count is non-zero

---
 library.scm | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/library.scm b/library.scm
index 199057f7..edee62aa 100644
--- a/library.scm
+++ b/library.scm
@@ -5002,10 +5002,11 @@ EOF
       (unless (null? tasks)
 	(for-each (lambda (t) (t)) tasks)
 	(loop))))
-  (when (##sys#debug-mode?)
-    (##sys#print "[debug] forcing finalizers...\n" #f ##sys#standard-error))
-  (when (chicken.gc#force-finalizers)
-    (##sys#force-finalizers)))
+  (when (fx> (##core#inline "C_i_live_finalizer_count") 0)
+    (when (##sys#debug-mode?)
+      (##sys#print "[debug] forcing finalizers...\n" #f ##sys#standard-error))
+    (when (chicken.gc#force-finalizers)
+      (##sys#force-finalizers))))
 
 (set! chicken.base#exit-handler
   (make-parameter
-- 
2.21.0

Reply via email to