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

Bert Freudenberg bert at impara.de
Sun Jul 23 13:52:09 UTC 2006


Am 21.07.2006 um 18:39 schrieb Andrew Tween:

> ..
>> 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

Thanks. This stuff is hard to measure consistently because  
finalization differs from VM to VM and is rather unpredictable. But  
my open-coded version at least should be easily understandable.

Could anybody please take care to get this into 3.9?

- Bert -




More information about the Squeak-dev mailing list