Raymond Toy pushed to branch issue-240-subsetp-with-hash-table at cmucl / cmucl
Commits: d1e97d99 by Raymond Toy at 2023-08-21T08:10:45-07:00 Fix type-init problem and set min length to 150 for subsetp
I was wrong about `type-init` having hashtables available. The issue was `*min-list-length-for-hashtable*` not being defined during `type-init`. Also, some timing tests indicate that we need a list length of about 150 for the hashtable implementation to be faster than the list implementation.
So, add a new variable `*min-list-length-for-subsetp-hashtable*` with a default value of 150. A `cold-init-form` is added so it's available during `type-init`.
The variable `*allow-hashtable-for-set-functions*` is removed because we don't need it anymore.
Also, as a test, I set `*min-list-length-for-subsetp-hashtable*` to 10, and we were still able to build lisp without problems.
- - - - -
4 changed files:
- src/code/lispinit.lisp - src/code/list.lisp - src/code/save.lisp - src/code/type.lisp
Changes:
===================================== src/code/lispinit.lisp ===================================== @@ -347,9 +347,6 @@ #+gengc (setf conditions::*handler-clusters* nil) (setq intl::*default-domain* "cmucl") (setq intl::*locale* "C") - ;; During init, we can't use hashtables to speed up the set - ;; functions. In particular, subsetp is used in type-init. - (setq lisp::*allow-hashtable-for-set-functions* nil)
;; Many top-level forms call INFO, (SETF INFO). (print-and-call c::globaldb-init)
===================================== src/code/list.lisp ===================================== @@ -989,8 +989,6 @@ (rplacd splicex (cdr x))) (setq splicex x)))))
-(defvar *allow-hashtable-for-set-functions* t) - (declaim (start-block shorter-list-to-hashtable subsetp))
(defun shorter-list-to-hashtable (list1 list2 key test test-not) @@ -1013,7 +1011,7 @@ (lst2 list2 (cdr lst2))) ((or (null lst1) (null lst2)) (values len (if (null lst1) list1 list2)))) - (when (< min-length *min-list-length-for-hashtable*) + (when (< min-length kernel::*min-list-length-for-subsetp-hashtable*) (return-from shorter-list-to-hashtable nil)) (let ((hashtable (make-hash-table :test hash-test :size min-length))) (dolist (item shorter-list) @@ -1031,7 +1029,7 @@ ;; take care to disable this for the kernel.core. SAVE will set ;; this to true when it's safe to use hash tables for SUBSETP. (multiple-value-bind (hashtable shorter-list) - (when *allow-hashtable-for-set-functions* + (when t (shorter-list-to-hashtable list1 list2 key test test-not)) (cond (hashtable (cond ((eq shorter-list list1)
===================================== src/code/save.lisp ===================================== @@ -320,8 +320,6 @@ (intl::setlocale) (ext::process-command-strings process-command-line) (setf *editor-lisp-p* nil) - ;; Allow using hashtables to speed up the set functions - (setf lisp::*allow-hashtable-for-set-functions* t) (macrolet ((find-switch (name) `(find ,name *command-line-switches* :key #'cmd-switch-name
===================================== src/code/type.lisp ===================================== @@ -377,6 +377,14 @@ (cold-load-init (setq *use-implementation-types* t)) (declaim (type boolean *use-implementation-types*))
+(defvar *min-list-length-for-subsetp-hashtable* 150 + "The minimum length of either list argument for subsetp where a + hashtable is used to speed up processing instead of using a basic + list implementation. This value was determined by experimentation.") + +(cold-load-init (setq *min-list-length-for-subsetp-hashtable* 150)) +(declaim (type fixnum *min-list-length-for-subsetp-hashtable*)) + ;;; DELEGATE-COMPLEX-{SUBTYPEP-ARG2,INTERSECTION} -- Interface ;;; ;;; These functions are used as method for types which need a complex
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/d1e97d9930f50e3781668768...