tracked-tools / tracked-built-ins

Tracked versions of JavaScript's built-in classes
MIT License
128 stars 24 forks source link

chore: Add performance regression test for TrackedArray #414

Open MichalBryxi opened 7 months ago

MichalBryxi commented 7 months ago

Crux

Performance tests

Other tests

TODOs

Relates to: #405

MichalBryxi commented 7 months ago

Note: this PR is based on this discussion and at the moment it should fail as we're in known non-performant situation. This is merely to track the situation and see when we get to a better place.

lifeart commented 7 months ago

Possible fix here (gives only 2.3-3x regression, instead of 100x) (inspired by https://github.com/vuejs/vue/blob/bed04a77e575d6c4c1d903f60087dca874f7213e/src/core/observer/array.ts#L17)

addon/src/-private/array.ts

    return new Proxy(clone, {
      get(target, prop /*, _receiver */) {
        let index = convertToInt(prop);
+        if (prop === 'splice') {
+          return (...args) => {
+            try {
+              return new TrackedArray(target.splice(...args));
+            } finally {
+              setValue(self.#collection, null);
+            }
+          };
        }
MichalBryxi commented 7 months ago

Oh wow, with your change I'm getting for 10M items:

Before (best case) = 2953ms After (worst case) = 7.89ms

So if i can potato with math, it's 374.2x improvement 🤯