Skip to content

Commit c19b59b

Browse files
🚴 perf(cache): Avoid trashing the GC in rare cases.
1 parent 9033dfb commit c19b59b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/0-core/measure/cache.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import {CachedMeasure} from './index.js';
22

3+
const CACHE = new WeakMap();
4+
35
export function cache(M) {
4-
return M instanceof CachedMeasure ? M : new CachedMeasure(M);
6+
if (CACHE.has(M)) return CACHE.get(M);
7+
8+
const cM = new CachedMeasure(M);
9+
CACHE.set(M, cM);
10+
CACHE.set(cM, cM);
11+
return cM;
512
}

0 commit comments

Comments
 (0)