Re: Euphoria bug
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Sep 15, 2005
- 562 views
On Thu, 15 Sep 2005 11:20:08 -0700, Bob Thompson <guest at RapidEuphoria.com> wrote: >Are you sure Pete? It still runs slow on 2.4, but yes, I see it does speed it up on 2.5. However, it is obviously only working by luck. I now think that the problem is with ref counts on temp (hidden) vars. Consider this:
for n = 1 to repeats do s[999][999] = n tmp = s[999] data = tmp[999] end for
This runs like a dog, and I would expect it to. The problem is that s[999] gets a refcount of 2, so storing in the 999'th element of s[999] must clone it, every iteration bar 1. IE s[999][999] = n must set s[999] to {.....,n} but leave tmp set to {......,n-1}, [see PS] If you insert tmp=0 just before the end for, it runs 100 times faster. It runs 100 times faster because the refcount on s[999] is put back down to 1 so it does not need to be cloned, ever. In fact, the interpreter uses a temp var in much the same way as above, only it really ought to remove any ref count side effects once it has done with using the temp var. Unrolling the data = s[999][999] statement in this case is only doing what the interpreter would do internally, so it will be just (or at least almost) as fast as can be. Hope that makes sense, Pete PS I can tell my desc of s[999] is not quite right; maybe it needs two clones every iteration, but I'm tired and I'm late already, and you get the idea, I'm sure. PPS I might have a look at eu.ex tomorrow.