Re: Two numbers
"Yuri Davidovsky (as work at disclosure dot ie)" <[email protected]> Sat, 11 Apr 2026 12:47:40 +0200
| Newsgroups | gmane.lisp.lispworks.general |
|---|---|
| Message-ID | <[email protected]> |
> On 11 Apr 2026, at 12:14, Tim Bradshaw (as tfb at tfeb dot org) <[email protected]> wrote: > > the only thing I can think of is that LW does slightly better 2d-array access While it could be a reason for the difference, there isn’t much wiggle room for optimising 2D array access. Underneath all arrays are 1D arrays, and when you have a 2D array of the size (10 10) created by (defvar arr (make-array '(10 10) :initial-element 'moo)) and then access an element by (aref arr 3 5) what you undoubtedly know you are in fact doing is (defvar arr (make-array 100 :initial-element 'moo)) and then (aref arr (+ (* 3 10) 5)) There is really no way to get array access wrong to an extent of it making a performance difference compared to two distinct implementations. I do not have any guesses how LW could match the performance of SBCL in this particular case, but it is not very likely that it is due to SBCL not accessing 2D array elements efficiently. Now, there are fused multiply-add operations on the CPU level where an expression similar to (+ (* 3 10) 5) could be simplified to a single instruction (although that may introduce a latency of 1 or 2 ticks) and which could in turn make a difference in array access efficiency, but my observations show that LW never uses FMA operations. I did not check how it accesses 2D arrays specifically however, so if it does that using the fused operation, while SBCL doesn’t, you could shave yourself off a single cycle of overhead.