(nthcdr most-positive-fixnum (list 1 2 3)) very slow

Bug #1852917 reported by Karsten Poeck
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
New
Undecided
Unassigned

Bug Description

(nthcdr most-positive-fixnum (list 1 2 3)) seems to run for ages
(nthcdr (1+ most-positive-fixnum) (list 1 2 3)) works fine

(nth most-positive-fixnum (list 1 2 3)) same problem
(nth (1+ most-positive-fixnum) (list 1 2 3)) also fine

(time (nthcdr 10000000000 (list 1 2 3))) -> 13 seconds on my machine, so the calculation probably returns eventually

The follwing fix for src/code/list.lisp seems to solve this, running the ansi-tests before and after gives the same result.

diff src/code/list.lisp src/code/list-patched.lisp
204a205,206
> (when (null result)
> (return nil))
250c252
< ((not (plusp i)) result))))
---
> ((or (not (plusp i)) (null result)) result))))

* (lisp-implementation-version)
"1.5.8"
* (machine-type)
"X86-64"
* (machine-version)
"Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz"
* (print *features*)

(:QUICKLISP :SB-BSD-SOCKETS-ADDRINFO :ASDF3.3 :ASDF3.2 :ASDF3.1 :ASDF3 :ASDF2
 :ASDF :OS-MACOSX :OS-UNIX :NON-BASE-CHARS-EXIST-P :ASDF-UNICODE :X86-64
 :64-BIT :ALIEN-CALLBACKS :ANSI-CL :AVX2 :BSD :C-STACK-IS-CONTROL-STACK
 :CALL-SYMBOL :COMMON-LISP :COMPACT-INSTANCE-HEADER :COMPARE-AND-SWAP-VOPS
 :CYCLE-COUNTER :DARWIN :FP-AND-PC-STANDARD-SAVE :GENCGC :IEEE-FLOATING-POINT
 :IMMOBILE-CODE :IMMOBILE-SPACE :INODE64 :INTEGER-EQL-VOP :LINKAGE-TABLE
 :LITTLE-ENDIAN :MACH-EXCEPTION-HANDLER :MACH-O :OS-PROVIDES-BLKSIZE-T
 :OS-PROVIDES-DLADDR :OS-PROVIDES-DLOPEN :OS-PROVIDES-PUTWC
 :OS-PROVIDES-SUSECONDS-T :PACKAGE-LOCAL-NICKNAMES :RELOCATABLE-HEAP :SB-DOC
 :SB-EVAL :SB-LDB :SB-PACKAGE-LOCKS :SB-SIMD-PACK :SB-SIMD-PACK-256
 :SB-SOURCE-LOCATIONS :SB-THREAD :SB-UNICODE :SBCL :STACK-ALLOCATABLE-CLOSURES
 :STACK-ALLOCATABLE-FIXED-OBJECTS :STACK-ALLOCATABLE-LISTS
 :STACK-ALLOCATABLE-VECTORS :STACK-GROWS-DOWNWARD-NOT-UPWARD
 :UNDEFINED-FUN-RESTARTS :UNIX :UNWIND-TO-FRAME-AND-CALL-VOP)

uname -a
Darwin karsten-poecks-macbook-pro.local 18.7.0 Darwin Kernel Version 18.7.0: Sat Oct 12 00:02:19 PDT 2019; root:xnu-4903.278.12~1/RELEASE_X86_64 x86_64

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

But that slows down the normal use case.

Revision history for this message
Karsten Poeck (kpoeck) wrote :

What about
(if (> n 100000) ;or any other threshold
    (code-path-testing-end-of-list-too)
    (old-code-path))

That would be 1 test more, but not in the loop

Revision history for this message
Paul F. Dietz (paul-f-dietz) wrote :

Similar to 1738071

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.