From cdf964ea85bce17399b5c44a82682340b1b01acb Mon Sep 17 00:00:00 2001 From: Malte Ubl Date: Sun, 11 Oct 2026 15:20:43 -0700 Subject: [PATCH] Allocate plain map headers out of line Map construction inlines into compiled callers, and the inline small-allocator path (with its clearing of recycled blocks) added 37 KB to tsc-ts across its constructors and init functions. A noinline helper keeps those call sites as small as the libc calloc call they had: tsc-ts text is now +5.6 KB over origin/main for this branch. --- packages/runtime/src/scr_map.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/runtime/src/scr_map.c b/packages/runtime/src/scr_map.c index bebcbd9e3..a5a0cb62c 100644 --- a/packages/runtime/src/scr_map.c +++ b/packages/runtime/src/scr_map.c @@ -666,6 +666,12 @@ ScrMap *scr_map_new(ScrMapKeyKind key_kind, ScrMapValKind val_kind, return scr_map_new_typed(key_kind, val_kind, NULL, NULL, NULL, val_retain, val_release, val_trace); } +/* Map construction inlines into its callers; keeping the header allocation + * out of line keeps those call sites as small as the libc call they had. */ +static __attribute__((noinline)) ScrMap *scr_map_alloc_plain(void) { + return scr_mem_calloc(sizeof(ScrMap)); +} + ScrMap *scr_map_new_typed(ScrMapKeyKind key_kind, ScrMapValKind val_kind, void *(*key_retain)(void *), void (*key_release)(void *), ScrTraceFn key_trace, @@ -677,7 +683,7 @@ ScrMap *scr_map_new_typed(ScrMapKeyKind key_kind, ScrMapValKind val_kind, static const ScrCycType cyc_type = { &scr_map_trace, &scr_map_gcfree, SCR_CYC_KIND_MAP }; m = scr_cyc_alloc(sizeof *m, &cyc_type); } else { - m = scr_mem_calloc(sizeof *m); + m = scr_map_alloc_plain(); if (!m) scr_map_oom(); } m->rc = 1;