Scripting: key calls fetch only the key they need, so removeKey stays fast (#814)
Every key call (removeKey, keyTime, keyValue, setInterpolationTypeAtKey…) looked its key up through `__keys()`, which serialised the whole key list, eases and tangents included, on each call. Removing keys one by one was therefore quadratic: about 100 ms per removeKey on a 2,000-key property. The `keys` query now takes an optional `index` and returns just that key with the count; `__key` uses it. removeKey on 2,000 keys drops from 103.7 ms to 0.4 ms (release, Windows 11 aarch64). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
470ea7a3af
commit
b2cf845624
@@ -828,10 +828,11 @@ Property.prototype.property = function () { return null; };
|
||||
};
|
||||
P.__keys = function () { return __get("keys", { comp: this.__layer.__comp, layer: this.__layer.__id, uid: this.__uid }); };
|
||||
P.__key = function (i) {
|
||||
var k = this.__keys();
|
||||
i = __num(i, "keyIndex");
|
||||
if (i < 1 || i > k.length || Math.floor(i) !== i) throw __err("keyIndex " + i + " is out of range 1.." + k.length);
|
||||
return k[i - 1];
|
||||
// Only the key asked for: fetching the whole list made every key call linear (#814).
|
||||
var r = i >= 1 && Math.floor(i) === i ? __get("keys", { comp: this.__layer.__comp, layer: this.__layer.__id, uid: this.__uid, index: i - 1 }) : null;
|
||||
if (!r || !r.key) throw __err("keyIndex " + i + " is out of range 1.." + (r ? r.count : this.numKeys));
|
||||
return r.key;
|
||||
};
|
||||
// Script value → engine JSON for `prop.set` / `prop.addKey`.
|
||||
P.__toEngine = function (v, info, time) {
|
||||
|
||||
Reference in New Issue
Block a user