What I was hoping was that in the case of a generic sequence, the extracted procedures would be specific to the underlying sequence. For example, the procedures returned from sequence-generate for a vector would be (highly) optimized for vectors. But, I have the advantage of arguing from a point of ignorance.<br>
<br><div class="gmail_quote">On Thu, Sep 10, 2009 at 9:18 AM, Matthew Flatt <span dir="ltr"><<a href="mailto:mflatt@cs.utah.edu">mflatt@cs.utah.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
When you use `in-vector', the expansion of `for' uses `vector-ref' etc.<br>
directly, so those operations can be inlined by the JIT.<br>
<br>
When you use a generic sequence, the expansion of `for' extracts a set<br>
of procedures from the sequence. The compiler can't tell that the<br>
extracted procedures will sometimes be `vector-ref' etc.<br>
<div><div></div><div class="h5"><br>
At Thu, 10 Sep 2009 09:03:24 -0600, Doug Williams wrote:<br>
> Actually, I'd like to dig into the sequence code (specifically,<br>
> sequence-generate) that should give you the sequencing function dynamically.<br>
> I'm not sure why it isn't as efficient as anything the for macro can<br>
> generate for vectors.<br>
><br>
> On Thu, Sep 10, 2009 at 8:47 AM, Jakub Piotr Cłapa <<a href="mailto:jpc-ml@zenburn.net">jpc-ml@zenburn.net</a>>wrote:<br>
><br>
> > On 09-09-10 16:30, Doug Williams wrote:<br>
> ><br>
> >> It's interesting that if I use (in-vector ...) in the for/fold<br>
> >> statements, the times for the for/fold version are about the same as for<br>
> >> the (uglier) do version (with vector-refs). [This one probably would<br>
> >> benefit from Matthew's performance improvements.] Actually using it<br>
> >> would mean giving up the flexibility in going to sequences in the first<br>
> >> place, but it means there is some hope of eventually getting the same<br>
> >> performance for the sequence versions (at least for vectors).<br>
> >><br>
> >> using in-vector in the for<br>
> >> cpu time: 266 real time: 265 gc time: 0<br>
> >> cpu time: 250 real time: 250 gc time: 47<br>
> >><br>
> >> current science collection routines<br>
> >> cpu time: 250 real time: 249 gc time: 0<br>
> >> cpu time: 218 real time: 218 gc time: 16<br>
> >><br>
> >> It would be nice if (for ((x some-vector)) ...) and (for ((x (in-vector<br>
> >> some-vector))) ...) had similar performance. I realize that at expansion<br>
> >> time the latter knows to expect a vector while the former does not and<br>
> >> can generate code accordingly. But, I can dream.<br>
> >><br>
> ><br>
> > AFAIU you could special case vectors (duplicating the code) if you expect<br>
> > them to be used frequently. Probably a for-like macro expanding into<br>
> > shortcuts for specified fast iterators would be nice to have. Something like<br>
> ><br>
> > (for ([x (in (list vector string) lst)])<br>
> > x)<br>
> ><br>
> > would expand to<br>
> ><br>
> > (cond<br>
> > [(list? x) (for ([x (in-list lst)]) x)]<br>
> > ...<br>
> > [else (for ([x lst]) x)])<br>
> ><br>
> > PS. And what about generating such special cases by evaling a dynamically<br>
> > generated lambda at runtime? I guess it would make really long iterations<br>
> > faster but the eval overhead would kill the performance for short ones?<br>
> ><br>
> > --<br>
> > regards,<br>
> > Jakub Piotr Cłapa<br>
> ><br>
> > _________________________________________________<br>
> > For list-related administrative tasks:<br>
> > <a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme" target="_blank">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br>
> ><br>
> _________________________________________________<br>
> For list-related administrative tasks:<br>
> <a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme" target="_blank">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br>
</div></div></blockquote></div><br>