very long comlillation time

Bug #1992349 reported by Mykola Matvyeyev
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Undecided
Unassigned

Bug Description

1. Compilation time increases greatly when sequentially add lines to the cond form (see below).

I would like to get less compilation time.

(defun cond-bug (value)
  "Square brackets contain compilation time"
 (cond
   ((< value 0 ) :one) ; [0.02 secs]
   ((< 0 value 100 ) :two) ; [0.02 secs]
   ((< 100 value 200 ) :three) ; [0.03 secs]
   ((< 200 value 300 ) :four) ; [0.04 secs]
   ((< 300 value 400 ) :five) ; [0.06 secs]
   ((< 400 value 500 ) :six) ; [0.15 secs]
   ((< 500 value 600 ) :seven) ; [0.25 secs]
   ((< 600 value 700 ) :eight) ; [0.51 secs]
   ((< 700 value 800 ) :nine) ; [0.98 secs]
   ((< 800 value 900 ) :ten) ; [1.64 secs]
   ((< 900 value 1000 ) :eleven) ; [2.76 secs]
   ((< 1000 value 1100 ) :twelve) ; [4.35 secs]
   ((< 1100 value 1200 ) :thirteen) ; [6.75 secs]
   ((< 1200 value 1300 ) :fourteen) ; [9.95 secs]
   ((< 1300 value 1400 ) :fifteen) ; [14.38 secs]
   ((< 1400 value 1500 ) :sixteen) ; [19.89 secs]
   ((< 1500 value 1600 ) :seventeen); [29.36 secs]
   ((< 1600 value 1700 ) :eighteen) ; [41.66 secs]
   ((< 1700 value 1800 ) :nineteen) ; [53.28 secs]
   #+nil((< 1800 value 1900 ) :twenty) ; [65.26 secs]
   ))

2. $ sbcl --version
SBCL 2.2.9

3. $ uname -a
MINGW64_NT-10.0-22621 uakazi-note 3.3.6-341.x86_64 2022-09-20 22:07 UTC x86_64 Msys

4. *FEATURES*
(:QUICKLISP :ASDF3.3 :ASDF3.2 :ASDF3.1 :ASDF3 :ASDF2 :ASDF :OS-WINDOWS
 :NON-BASE-CHARS-EXIST-P :ASDF-UNICODE :X86-64 :GENCGC :64-BIT :ANSI-CL
 :COMMON-LISP :IEEE-FLOATING-POINT :LITTLE-ENDIAN :PACKAGE-LOCAL-NICKNAMES
 :SB-LDB :SB-PACKAGE-LOCKS :SB-SAFEPOINT :SB-THREAD :SB-UNICODE :SBCL :WIN32)

Revision history for this message
Stas Boukarev (stassats) wrote :

That's another instance of the constraint changes for join-type-constraints slowing things down.

Revision history for this message
Christophe Rhodes (csr21-cantab) wrote :

I appreciate that this might be a reduced test case, and that the real situation might not look like this -- and that also the behaviour is bad in any case. But just in case this helps make progress in the real case, note that the integer ranges are not contiguous -- the type of VALUE at the default branch of the COND includes every round hundred value. I found that

(defun cond-bug (value)
  "Square brackets contain compilation time"
 (cond
   ((< value 0 ) :one) ; [0.02 secs]
   ((< -1 value 100 ) :two) ; [0.02 secs]
   ((< 99 value 200 ) :three) ; [0.03 secs]
   ((< 199 value 300 ) :four) ; [0.04 secs]
   ((< 299 value 400 ) :five) ; [0.06 secs]
   ((< 399 value 500 ) :six) ; [0.15 secs]
   ((< 499 value 600 ) :seven) ; [0.25 secs]
   ((< 599 value 700 ) :eight) ; [0.51 secs]
   ((< 699 value 800 ) :nine) ; [0.98 secs]
   ((< 799 value 900 ) :ten) ; [1.64 secs]
   ((< 899 value 1000 ) :eleven) ; [2.76 secs]
   ((< 999 value 1100 ) :twelve) ; [4.35 secs]
   ((< 1099 value 1200 ) :thirteen) ; [6.75 secs]
   ((< 1199 value 1300 ) :fourteen) ; [9.95 secs]
   #+nil ((< 1300 value 1400 ) :fifteen) ; [14.38 secs]
   #+nil ((< 1400 value 1500 ) :sixteen) ; [19.89 secs]
   #+nil ((< 1500 value 1600 ) :seventeen); [29.36 secs]
   #+nil ((< 1600 value 1700 ) :eighteen) ; [41.66 secs]
   #+nil ((< 1700 value 1800 ) :nineteen) ; [53.28 secs]
   #+nil((< 1800 value 1900 ) :twenty) ; [65.26 secs]
   ))

compiled 50 times faster than the equivalent with x00 in the clauses

Revision history for this message
Stas Boukarev (stassats) wrote :

I pushed another optimization, it goes from 14 seconds to 3.5. Still too much for such a small form.

Revision history for this message
Charles (karlosz) wrote :

Now this form takes almost no time to compiler, so closing. (It must be some of the new type system changes that fixed this - it doesn't seem constraint related.)

Changed in sbcl:
status: New → Fix Committed
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.