mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-31 07:38:24 +00:00
Expressions: the kept layers are bounded like the runtime's scripts
This commit is contained in:
1 parent
2f2ebbdedb
commit
ad6b87c60d
1 file changed
+19
-6
@@ -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; }
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
Reference in new issue
Block a user