perf(javascript): skip checkpoint encoding without reuse capacity

Runtimes without a reported heap limit (Bun) retain nothing, yet discovery
still encoded every complete checkpoint before checking capacity. Check the
remaining capacity first.

Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
This commit is contained in:
gensokyo-devandgensokyo-dev authored and Ysopwnable committed 2026-11-23 23:40:19 +08:00
1 parent c2779ae514
commit d78eee196a
1 file changed
+9 -6
@@ -114,6 +114,14 @@ export const retainJavaScriptStaticCheckpoint = (
key: string,
facts: JavaScriptStaticAnalysis,
): void => {
const previous = retainedStatics.get(key);
if (previous !== undefined) {
retainedStatics.delete(key);
retainedStaticBytes -= previous.retainedBytes;
}
// Skip encoding where reuse is disabled or no capacity remains.
const capacity = staticReuseCapacityBytes();
if (retainedStaticBytes >= capacity) return;
let text: string;
let retainedBytes: number;
try {
@@ -127,12 +135,7 @@ export const retainJavaScriptStaticCheckpoint = (
// the same refusal, so retention never fails preload discovery.
return;
}
const previous = retainedStatics.get(key);
if (previous !== undefined) {
retainedStatics.delete(key);
retainedStaticBytes -= previous.retainedBytes;
}
if (retainedStaticBytes + retainedBytes > staticReuseCapacityBytes()) return;
if (retainedStaticBytes + retainedBytes > capacity) return;
retainedStatics.set(key, {
text,
retainedBytes,