[plt-scheme] Statistics for Sequences

From: Doug Williams (m.douglas.williams at gmail.com)
Date: Thu Sep 10 12:12:31 EDT 2009

>
> Maybe the issue of when "just in time" is. The JIT currently compiles
> at the granularity of `lambda', and it compiles each `lambda' only
> once.
>

> So, although `sequence-generate' may produce vector-specific operations
> for a given invocation of the `for' loop, the JIT produces a generic
> function call to the vector-specific operation (which might not be
> vector-specific next time around).
>

So, the vector-specific lambda(s) returned by sequence-generate are
optimized when they are first seen by the JIT compiler. But, there are
additional optimizations (for the sequencing operation) that would not be
possible within the for itself because there is not much left but generic
function invocations. Specifically in the case of vectors, by having the for
macro generate the increment and test of the index and the vector-refs, the
JIT compiler can generate specific instructions for those operations. While,
for a generic sequence that happens to be a vector, there is no alternative
but to generate a call to see if more data is available and, if there is,
another call to get the next element of the sequence.


> One possibility for improvement, then, is to change the JIT strategy to
> generate code later and more frequently.
>
>
But, writing some kind of 'dispatching for' macro is probably the only
near-term way of getting nearly the same performance for a generic sequence
that happens to be a vector and a 'for' specific written for a vector.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090910/9c2735c1/attachment.html>

Posted on the users mailing list.