master: Speed up looking in the ctype-list-hash-set
snuglas via Sbcl-commits <[email protected]> Fri, 31 Jul 2026 03:14:06 +0000
| Newsgroups | gmane.lisp.steel-bank.cvs |
|---|---|
| Message-ID | <[email protected]> |
The branch "master" has been updated in SBCL:
via ed2340f71ac49df95e0fe4fd201f3ac5a0e3c13b (commit)
from 1285374c8c7ae0538d70803fae11c9f627cfb3ad (commit)
- Log -----------------------------------------------------------------
commit ed2340f71ac49df95e0fe4fd201f3ac5a0e3c13b
Author: Douglas Katzman <[email protected]>
Date: Fri Jul 31 03:13:59 2026 +0000
Speed up looking in the ctype-list-hash-set
In a particular compile-file, this hashset grew to have a maximum probe
sequence length of 14, and with 2 million lookups, it was a performance
bottleneck. A better hash mixer cut the max PSL down to 7.
---
src/code/type-class.lisp | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/code/type-class.lisp b/src/code/type-class.lisp
index 2699471d9..7e4b6b952 100644
--- a/src/code/type-class.lisp
+++ b/src/code/type-class.lisp
@@ -623,6 +623,12 @@
do (setq res (logxor (ash res -1) (type-%bits type)))
;; This returns a positive number so that it can be passed to MIX
finally (return (ldb (byte (1- ctype-hash-size) 0) res))))
+(defun mix-hash-ctype-list (types)
+ (declare (optimize (speed 3) (safety 0)))
+ (loop with res of-type (and sb-xc:fixnum unsigned-byte) = 0
+ for type in types
+ do (setq res (mix (type-hash-value type) res))
+ finally (return (ldb (byte (1- ctype-hash-size) 0) res))))
(defun hash-ctype-set (types) ; ctype list hashed order-insensitively
(let ((hash (type-%bits (car types)))
@@ -643,7 +649,7 @@
(and (= (length a) (length b)) (every (lambda (x) (memq x b)) a)))
(define-load-time-global *ctype-list-hashset*
- (make-hashset 32 #'list-elts-eq #'hash-ctype-list :weakness t :synchronized t))
+ (make-hashset 32 #'list-elts-eq #'mix-hash-ctype-list :weakness t :synchronized t))
(define-load-time-global *ctype-set-hashset*
(make-hashset 32 #'ctype-set= #'hash-ctype-set :weakness t :synchronized t))
-----------------------------------------------------------------------
hooks/post-receive
--
SBCL