go reuses frames

This commit is contained in:
2026-02-15 19:45:17 -06:00
parent 23b201bdd7
commit 7fc4a205f6
2 changed files with 53 additions and 24 deletions

View File

@@ -1492,6 +1492,10 @@ void gc_scan_object (JSContext *ctx, void *ptr, uint8_t *from_base, uint8_t *fro
allow_grow: if true, grow heap when recovery is poor
alloc_size: the allocation that triggered GC — used to size the new block */
int ctx_gc (JSContext *ctx, int allow_grow, size_t alloc_size) {
#ifdef DUMP_GC_TIMING
struct timespec gc_t0, gc_t1;
clock_gettime(CLOCK_MONOTONIC, &gc_t0);
#endif
JSRuntime *rt = ctx->rt;
size_t old_used = ctx->heap_free - ctx->heap_base;
size_t old_heap_size = ctx->current_block_size;
@@ -1692,6 +1696,16 @@ int ctx_gc (JSContext *ctx, int allow_grow, size_t alloc_size) {
ctx->gc_bytes_copied += new_used;
size_t recovered = old_used > new_used ? old_used - new_used : 0;
#ifdef DUMP_GC_TIMING
clock_gettime(CLOCK_MONOTONIC, &gc_t1);
double gc_ms = (gc_t1.tv_sec - gc_t0.tv_sec) * 1000.0 +
(gc_t1.tv_nsec - gc_t0.tv_nsec) / 1e6;
fprintf(stderr, "GC #%u: %.2f ms | copied %zu KB | old %zu KB -> new %zu KB | recovered %zu KB (%.0f%%)\n",
ctx->gc_count, gc_ms,
new_used / 1024, old_used / 1024, new_size / 1024,
recovered / 1024,
old_used > 0 ? (100.0 * recovered / old_used) : 0.0);
#endif
ctx->heap_base = to_base;
ctx->heap_free = to_free;