[FIX] Re: DependentsArray size and subscript is out of bounds

Andrew Tween amtween at hotmail.com
Fri Jul 21 16:39:38 UTC 2006


..
> if you try this:
>
> | a |
> a := DependentsArray new.
> [1 to: 1000 do: [:i | a := a copyWith: Object new]] timeToRun
>
> The old code will complete that in less than a second. Your version
> takes 3 minutes (I think because of hidden size calls on the
> DependentsArray which are very expensive). This is not a realistic
> use case, but still ;-)

Well...the old code fails within a second , at least on my machine ;)
With a slightly different test...
    | a |
    a := DependentsArray new.
    [1 to: 1000 do: [:i | a := a copyWith: i]] timeToRun.
I get these timings...
old code: 5.5 minutes
my fix: 5.6 minutes

>
> I suggest the following:
>
> copyWith: newElement
> "Re-implemented to not copy any niled out dependents."
> | copy i |
> copy := self class new: self size + 1.
> i := 0.
> self do: [:item | copy at: (i:=i+1) put: item].
> copy at: (i:=i+1) put: newElement.
> ^copy
>
> This appears to be even more efficient than the original. I'll attach
> the CS.

Using the same timing test as above, we have....

old code: 5.5 minutes
my fix: 5.6 minutes
your fix: 0.6 seconds

Congrats. I think that qualifies for 'speed-up' of the day (or month, or year,
or decade ?)
Cheers,
Andy

..



More information about the Squeak-dev mailing list