Skip to content

Commit e18ca84

Browse files
committed
[optim] introduce *pygc-threshold*
Substantially speedup even when not surrounded by with-pygc.
1 parent 68ac1f1 commit e18ca84

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/gil-gc.lisp

+3
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ This avoids inadvertent calls to DecRef during recursions.")
167167
;; FIXME: Do we leak this into the python-object finalizers?
168168
(defvar *pygc-enabled* t
169169
"If NIL, expects PYGC to be called manually by the user.")
170+
(defvar *pygc-threshold* 1000
171+
"Number of references in *PYTHON-NEW-REFERENCES* after which PYGC manipulates reference counts.")
170172

171173
(defmacro enable-pygc ()
172174
`(eval-when (:compile-toplevel :load-toplevel :execute)
@@ -194,6 +196,7 @@ This avoids inadvertent calls to DecRef during recursions.")
194196
;; :do (let ((ptr (make-pointer addr)))
195197
;; (format t "~%At ~A with refcnt ~A:~% ~A"
196198
;; ptr count (lispify ptr))))
199+
(when (< (hash-table-count ht) *pygc-threshold*) (return-from pygc))
197200
(with-python-gil/no-errors
198201
(with-hash-table-iterator (ht-iter ht)
199202
(loop :do (multiple-value-bind (validp addr count) (ht-iter)

src/package.lisp

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#:%shared-library-from-ldflag)
55
(:export #:*internal-features*
66

7+
#:*pygc-threshold*
78
#:with-pygc
89
#:enable-pygc
910
#:disable-pygc

0 commit comments

Comments
 (0)