[Sbcl-devel] NREVERSE and REVERSE micro-optimization.

 [Sbcl-devel] NREVERSE and REVERSE micro-optimization. From: Karol Swietlicki - 2009-09-01 23:21:23 ```This is not that big of an improvement, but here goes. NREVERSE and REVERSE both perform run-time dispatch on type. Adding something like this: (deftransform reverse ((seq) (list)) `(sb-impl::list-reverse* seq)) (deftransform nreverse ((seq) (list)) `(sb-impl::list-nreverse* seq)) (deftransform reverse ((seq) (vector)) `(sb-impl::vector-reverse* seq)) (deftransform nreverse ((seq) (vector)) `(sb-impl::vector-nreverse* seq)) should take care of that. Another thing to consider would be the inlining the various -reverse* functions, but that is a different matter altogether. Thoughts? Karol Swietlicki ```

 [Sbcl-devel] NREVERSE and REVERSE micro-optimization. From: Karol Swietlicki - 2009-09-01 23:21:23 ```This is not that big of an improvement, but here goes. NREVERSE and REVERSE both perform run-time dispatch on type. Adding something like this: (deftransform reverse ((seq) (list)) `(sb-impl::list-reverse* seq)) (deftransform nreverse ((seq) (list)) `(sb-impl::list-nreverse* seq)) (deftransform reverse ((seq) (vector)) `(sb-impl::vector-reverse* seq)) (deftransform nreverse ((seq) (vector)) `(sb-impl::vector-nreverse* seq)) should take care of that. Another thing to consider would be the inlining the various -reverse* functions, but that is a different matter altogether. Thoughts? Karol Swietlicki ```
 Re: [Sbcl-devel] NREVERSE and REVERSE micro-optimization. From: Nikodemus Siivola - 2009-09-11 13:25:31 ```2009/9/2 Karol Swietlicki : > This is not that big of an improvement, but here goes. > > NREVERSE and REVERSE both perform run-time dispatch on type. > Adding something like this: > > (deftransform reverse ((seq) (list)) >  `(sb-impl::list-reverse* seq)) > (deftransform nreverse ((seq) (list)) >  `(sb-impl::list-nreverse* seq)) > (deftransform reverse ((seq) (vector)) >  `(sb-impl::vector-reverse* seq)) > (deftransform nreverse ((seq) (vector)) >  `(sb-impl::vector-nreverse* seq)) A patch along these lines would not be unwelcome. There are also other sequence functions which would benefit from similar attention, I believe. (Which is not to say this will not be done without someone sending in a patch, but...) Cheers, -- Nikodemus ```
 Re: [Sbcl-devel] NREVERSE and REVERSE micro-optimization. From: Tobias C. Rittweiler - 2009-09-15 10:09:52 ```Nikodemus Siivola writes: > 2009/9/2 Karol Swietlicki : >> This is not that big of an improvement, but here goes. >> >> NREVERSE and REVERSE both perform run-time dispatch on type. >> Adding something like this: >> >> (deftransform reverse ((seq) (list)) >>  `(sb-impl::list-reverse* seq)) >> (deftransform nreverse ((seq) (list)) >>  `(sb-impl::list-nreverse* seq)) >> (deftransform reverse ((seq) (vector)) >>  `(sb-impl::vector-reverse* seq)) >> (deftransform nreverse ((seq) (vector)) >>  `(sb-impl::vector-nreverse* seq)) > > A patch along these lines would not be unwelcome. There are also other > sequence functions which would benefit from similar attention, I > believe. > > (Which is not to say this will not be done without someone sending in > a patch, but...) Wouldn't it be better to solve this via inlining? Perhaps some form of conditionalized inlinig where inlining only happens if the type of a specific argument could be derived. -T. ```
 Re: [Sbcl-devel] NREVERSE and REVERSE micro-optimization. From: Nikodemus Siivola - 2009-09-15 11:25:47 ```2009/9/15 Tobias C. Rittweiler : > Wouldn't it be better to solve this via inlining? Perhaps some form of > conditionalized inlinig where inlining only happens if the type of a > specific argument could be derived. Yes and no: we don't have a mechanism for stuff like that, but if we had, I think it would find other uses as well. Something along the lines of (define-dispatch-function length (x) ((list) (list-length x)) ((vector) (vector-length x)) ((t) (sb-sequence:length x))) that generates both an out-of-line definition and the appropriate deftransform(s). I bet our users would like something like that as well. Cheers, -- Nikodemus ```
 Re: [Sbcl-devel] NREVERSE and REVERSE micro-optimization. From: Karol Swietlicki - 2009-09-16 05:09:57 ```2009/9/15 Nikodemus Siivola : > 2009/9/15 Tobias C. Rittweiler : >> Wouldn't it be better to solve this via inlining? Perhaps some form of >> conditionalized inlinig where inlining only happens if the type of a >> specific argument could be derived. > > Yes and no: we don't have a mechanism for stuff like that, but if we > had, I think it would find other uses as well. > > Something along the lines of > >  (define-dispatch-function length (x) >   ((list) >    (list-length x)) >   ((vector) >    (vector-length x)) >   ((t) >    (sb-sequence:length x))) > > that generates both an out-of-line definition and the appropriate > deftransform(s). I bet our users would like something like that as > well. > > Cheers, > >  -- Nikodemus Sound like fun. I'll give it a shot, once I finally get more than a couple of hours of time for myself (and deal with other SBCL stuff that I'm working on). Might as well get this done right. Karol Swietlicki ```