mirror of
git://git.code.sf.net/p/sbcl/sbcl
synced 2026-09-10 07:26:40 -04:00
This replaces the usual hash-table with a new storage representation that is almost always lockfree, and removes all complexity around assigning a unique ID to each finalized object. The ugly hack in cull_weak_hash_table_bucket() is no more. As the benchmark shows, with 4 threads we can create finalizers about 3x faster at the cost of about 1.5x more memory. Fixes lp#1998064 where finalizers are concerned, but if the bug exists more generally, this doesn't do anything for it.
42 lines
1.4 KiB
Common Lisp
42 lines
1.4 KiB
Common Lisp
(defun make-threads (semaphore nwriters nobjects)
|
|
(loop for i below nwriters
|
|
collect
|
|
(let ((list (loop repeat nobjects for j from 1
|
|
collect (cons i j))))
|
|
(sb-thread:make-thread
|
|
(lambda (things)
|
|
(sb-thread:wait-on-semaphore semaphore)
|
|
(dolist (thing things)
|
|
(finalize thing #'+)) ; a no-op finalizer
|
|
(mapc #'cancel-finalization things))
|
|
:arguments (list list)
|
|
:name (format nil "worker ~D" i)))))
|
|
|
|
(defun test-finalize+cancel (ntrials nwriters nobjects)
|
|
(dotimes (i ntrials)
|
|
(let* ((sem (sb-thread:make-semaphore))
|
|
(threads (make-threads sem nwriters nobjects)))
|
|
(sb-thread:signal-semaphore sem nwriters)
|
|
(mapc #'sb-thread:join-thread threads))))
|
|
|
|
(time (test-finalize+cancel 100 4 10000)) ; 100 trials, 4 threads, 10k objects per thread
|
|
#|
|
|
;; Old:
|
|
Evaluation took:
|
|
4.100 seconds of real time
|
|
10.704615 seconds of total run time (10.585181 user, 0.119434 system)
|
|
[ Run times consist of 0.017 seconds GC time, and 10.688 seconds non-GC time. ]
|
|
261.10% CPU
|
|
9,841,747,312 processor cycles
|
|
203,244,640 bytes consed
|
|
|
|
;; New:
|
|
Evaluation took:
|
|
1.179 seconds of real time
|
|
2.874184 seconds of total run time (2.756504 user, 0.117680 system)
|
|
[ Run times consist of 0.041 seconds GC time, and 2.834 seconds non-GC time. ]
|
|
243.77% CPU
|
|
2,830,553,292 processor cycles
|
|
353,720,608 bytes consed
|
|
|#
|