EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Expressions: the kept layers are bounded like the runtime's scripts
tylerjenningswad6b87c60da5
diff --git a/crates/expr/src/prelude.js b/crates/expr/src/prelude.jsindex 5671d3ec2..2fdcba110 100644--- a/crates/expr/src/prelude.js+++ b/crates/expr/src/prelude.js@@ -31,6 +31,7 @@ function __begin(t, v, c, l, path, uid, idx, fd, ti, tt, sv) {__seed = 0;__timeless = false;__projectInfo = null;+ __layersTrim();}function __finish(r) {@@ -563,13 +564,25 @@ function Layer(c, l) {// Layer `l` of comp `c`, made once per runtime: a callable Layer is dearer to make than a plain// object, so it is kept, and its info (`__info`) is read again in each evaluation.-// The kept layers are out of an expression's reach.-var __layer = (function () {- var layers = {};- return function (c, l) {+// The kept layers are out of an expression's reach, and bounded like the runtime's scripts: once+// `max` are kept, the layers after them aren't, and the next evaluation starts over+// (`__layersTrim`, so a layer stays the same object for a whole evaluation).+var __layer, __layersTrim;+(function () {+ var layers = {}, kept = 0, max = 4096;+ __layer = function (c, l) {// By comp, then layer: a `c + ':' + l` key costs more to build than the lookup saves.- var m = layers[c] || (layers[c] = {});- return m[l] || (m[l] = new Layer(c, l));+ var m = layers[c], f = m && m[l];+ if (f) return f;+ f = new Layer(c, l);+ if (kept < max) {+ (m || (layers[c] = {}))[l] = f;+ kept++;+ }+ return f;+ };+ __layersTrim = function () {+ if (kept >= max) { layers = {}; kept = 0; }};})();