ccl icon indicating copy to clipboard operation
ccl copied to clipboard

TYPEP with invalid types can be really slow

Open melisgl opened this issue 7 months ago • 0 comments

(typep 1 '(not (or junk junk2))) is almost a 100 times slower compared to other invalid types:

This is with Clozure Common Lisp Version 1.13 (v1.13) LinuxX8664:

CL-USER> (time (loop repeat 100 do
           (ignore-errors (typep 1 '(not (or junk junk2))))))
;Compiler warnings :
;   In an anonymous lambda form: Undefined type (NOT (OR JUNK JUNK2))
(LOOP REPEAT 100 DO (IGNORE-ERRORS (TYPEP 1 '(NOT (OR JUNK JUNK2)))))
took 819,513 microseconds (0.819513 seconds) to run.
       4,060 microseconds (0.004060 seconds, 0.50%) of which was spent in GC.
During that period, and with 8 available CPU cores,
     821,712 microseconds (0.821712 seconds) were spent in user mode
       3,836 microseconds (0.003836 seconds) were spent in system mode
 38,212,800 bytes of memory allocated.
NIL
CL-USER> (time (loop repeat 100 do
           (ignore-errors (typep 1 '(not (or junk junk))))))
;Compiler warnings :
;   In an anonymous lambda form: Undefined type (NOT (OR JUNK JUNK))
(LOOP REPEAT 100 DO (IGNORE-ERRORS (TYPEP 1 '(NOT (OR JUNK JUNK)))))
took 4,379 microseconds (0.004379 seconds) to run.
During that period, and with 8 available CPU cores,
     4,370 microseconds (0.004370 seconds) were spent in user mode
        11 microseconds (0.000011 seconds) were spent in system mode
 108,800 bytes of memory allocated.
NIL
CL-USER> (time (loop repeat 100 do
           (ignore-errors (typep 1 'junk))))
;Compiler warnings :
;   In an anonymous lambda form: Undefined type JUNK
(LOOP REPEAT 100 DO (IGNORE-ERRORS (TYPEP 1 'JUNK)))
took 1,026 microseconds (0.001026 seconds) to run.
During that period, and with 8 available CPU cores,
       995 microseconds (0.000995 seconds) were spent in user mode
        33 microseconds (0.000033 seconds) were spent in system mode
 40,000 bytes of memory allocated.
NIL
CL-USER> (time (loop repeat 100 do
           (ignore-errors (typep 1 '(not (and junk junk2))))))
;Compiler warnings :
;   In an anonymous lambda form: Undefined type (NOT (AND JUNK JUNK2))
(LOOP REPEAT 100 DO (IGNORE-ERRORS (TYPEP 1 '(NOT (AND JUNK JUNK2)))))
took 9,328 microseconds (0.009328 seconds) to run.
During that period, and with 8 available CPU cores,
     9,902 microseconds (0.009902 seconds) were spent in user mode
        55 microseconds (0.000055 seconds) were spent in system mode
 268,800 bytes of memory allocated.
NIL

melisgl avatar Apr 09 '25 08:04 melisgl