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.
This commit is contained in:
Malte Ubl
2026-10-11 16:30:23 -07:00
parent 2a7c22ae49
commit cdf964ea85
+7 -1
View File
@@ -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;