Just read up on it; the dsetel pass doesn't have that kind of magic.<br>Specifically,<br>- it can only handle fixed indexes;<br>- the resulting destructive update doesn't check the tuple size, so the elements must be updated in a descending-index order;<br>
- there must be no chance of GC kicking in between creation of the tuple and the destructive update (or else there might be introduced an old-generation-to-new-generation pointer).<br>So not only doesn't dsetel at present optimize setelement calls across a loop, it is not likely to get that ability in the future either.<br>
<br>Apparently dsetel is rather narrowly aimed at optimizing record updates; it doesn't try to be much cleverer than needed for that job.<br><br><div class="gmail_quote">2012/7/10 Erik Søe Sørensen <span dir="ltr"><<a href="mailto:eriksoe@gmail.com" target="_blank">eriksoe@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p>It can optimize setelement used in a loop? I'd be surprised, although pleasantly so.<br>
(I didn't even know it could handle non-fixed indexes, but then I am not generally very familiar with it.)<br>
One more thing to research...</p>
<div class="gmail_quote">Den 10/07/2012 10.10 skrev "Anthony Ramine" <<a href="mailto:n.oxyde@gmail.com" target="_blank">n.oxyde@gmail.com</a>>:<div><div class="h5"><br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I wouldn't be so sure about that, you need to check whether the destructive updates pass (dsetel) does its magic here.<br>
<br>
--<br>
Anthony Ramine<br>
<br>
Le 10 juil. 2012 à 01:50, Erik Søe Sørensen a écrit :<br>
<br>
> Using setelement is a bad idea, at least unless the tuples are very small: the cost in time and allocation is n^2.<br>
> A better scaling approach is to use tuple_to_list + map + list_to_tuple; that should be linear, and my guess is that it'd be faster even for small tuple sizes.<br>
> (For the actual n=4 case, I don't know which is better; must measure...)<br>
> /Erik<br>
</blockquote></div></div></div>
</blockquote></div><br>