Open and answer this issue on GitHub.
runtime, performance, decision · opened 2026-11-20 · updated 2026-11-20 · 0 comments
Found while a Counting global allocator in the nikaia binary costs +4.2 % instructions (#2368) Part of std::mem: allocations() and usage() per thread (ADR-400) (#2112)
A program pays for counting its allocations only where it reads the counts. Today every emitted program and (with #2368) the nikaia binary installs task_block::Counting (crates/unsafe/task-block/src/lib.rs), which on every alloc, dealloc and realloc adds to the thread’s TALLY (ADR-400 D1, D2) and to the running block’s outside (ADR-327 D9, D10).
tests/compiler/tests/byteset_every_search_is_the_byte_by_byte_one.nika)__rust_alloc grows from a jump to malloc to a framed function with two thread-local updates (the TLS reads are already direct %fs offsets, no __tls_get_addr).std::mem::allocations() / usage(), a test block that does, and a task with a memory budget (ADR-327 D15 reads outside).Counting only where the program (its closure of called functions) reaches mem::allocations, mem::usage or a budget, the system allocator otherwise; (b) one allocator with a counting switch read per call (cheaper, not free); (c) keep counting always and make it cheaper (one thread-local, count before the call so malloc is a tail call).A program that reads no counts and sets no budget runs with the system allocator (instruction count equal to it, measured), and one that reads them still gets ADR-400’s numbers (tests/compiler/tests/ test).