timfel / etoys-spur

A repository to track Etoys development, keep external sources, and build all-in-one bundles
MIT License
0 stars 0 forks source link

Kedama is very slow when creating turtles not at once #20

Open JensLincke opened 7 years ago

JensLincke commented 7 years ago

Each time a new turtle is created arrays are copied.... This is the same for creating 1 or 10000 turtles.

This makes it hard to write scripts that create new turtles... alternatively, scripts could somehow just activate or deactivate turtles that are already there. Which would mean that they don't have to be created.

addTurtlesCount: count ofPrototype: prototype for: aKedamaWorld randomize: randomizeFlag

    | index array defaultValue newArray oldCount |
    oldCount _ self size.
    arrays size > 100 ifTrue: [ self halt].
    self halt.
    info associationsDo: [:assoc |
        index _ assoc value.
        array _ arrays at: index.
        defaultValue _ prototype at: index.
        newArray _ array class new: count.
        newArray atAllPut: defaultValue.
        arrays at: index put: (array, newArray). "#JL #TODO this is a #Performance bug...."
    ].
    predicate _ arrays at: 7.
    predicate from: oldCount + 1 to: predicate size put: 1.

    self setInitialValueOf: #who from: oldCount + 1 to: self size for: aKedamaWorld.

    randomizeFlag ifTrue: [
        #(x y heading) do: [:name |
            self setInitialValueOf: name from: oldCount + 1 to: self size for: aKedamaWorld.
        ].
    ].
    whoTableValid _ false.
    kedamaWorld drawRequest.
timfel commented 7 years ago

I have a prototype implementation that simply makes KedamaFloatArray a subclass of OrderedCollection and use that for all arrays. This works, and creating and deleting turtles isn't too bad, but performance overall seems to be a little worse.