You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Which Sema/MIR sites create the 40,178 short-lived minted-keyed maps that take 90% of the compiler's 2.4 billion lookups #3093
From #3087's measurement (WITH_TRACE_HM_PROBES=1 with-stage2 check src/main.w): 2,617,994,401 map lookups at 1.17 slots each; 2,364,393,453 of them on 40,178 minted-keyed maps created and freed during the check (per-body or per-instance tables), against 147M on the symbol pool. Probing is not the cost; the lookup count is, and it is in the short-lived maps.
The runtime cannot name a creation site. Two routes:
WITH_TRACE_HM_PROBES=2: at with_hashmap_free, when a map's lookups exceed a threshold, print its counts with a backtrace of its creation (record rt_backtrace at with_hashmap_new when the switch is on).
Sema-side: count lookups per declared map field under a switch, keyed by the field name, in check_fn_body_with_sig_once's per-body tables.
Then: which lookups repeat per node per pass, which per-body tables could be one module-wide table with an epoch (the binding_use_epoch pattern already in SemaCheck.w), and the timing after.
Measured with the threshold mode (WITH_TRACE_HM_PROBES=1000000 with-stage2 check src/main.w, branch i3093): 104 maps were freed after a million or more lookups, carrying 2.26B of the 2.36B "freed before exit" lookups. By the frame that freed them:
freed from
maps
lookups
the top-level struct's drop at the end of main
42
1.44B
Zcu.compile_source_frontend_mode (a round's Sema going out of scope)
So the "short-lived maps" were a reading of the exit report, not a fact about the maps: the lookups are in Sema's module-wide tables. 61% of them live until the compilation's own drop at the end of main (they are freed "before exit" only in the ledger's sense); 28% are the tables of the extra Sema rounds that D89 (field types from use) and D93 (literal types from use) run over a module whose decisions change; 5% is rebuild_named_type_candidate_index, rebuilt nine times. The 40,178 small maps carry the remaining 4%.
The heaviest single table: a minted 4-byte-key map freed by a round's Sema after 306M lookups, 1520 live of 3569 entries in an 8192 index — a table with heavy remove traffic (tombstones), read 200k times per live entry. Second: a 12,062-entry minted map, 84M–87M lookups in each of two Semas (per-node type table, likely typed_expr_types).
What follows from this is not a hasher or probe change. Two leads, each its own issue: the re-check rounds (a quarter of all lookups re-derive the whole module to hear one decision), and the tombstone-heavy table (which Sema table has ~1500 live entries with constant insert/remove during a check, and whether it wants a stack or an epoch instead of a map).
Answered above: the lookup volume is Sema's module-wide tables (61% the final Semas', 28% the D89/D93 re-check rounds', 5% the type-candidate index rebuilt nine times), not many short-lived maps. The threshold mode that found it lands with the i3093 branch; the two leads are filed as their own issues.
Activity
ehartford commentedon Nov 8, 2026
Measured with the threshold mode (
WITH_TRACE_HM_PROBES=1000000 with-stage2 check src/main.w, branchi3093): 104 maps were freed after a million or more lookups, carrying 2.26B of the 2.36B "freed before exit" lookups. By the frame that freed them:mainZcu.compile_source_frontend_mode(a round'sSemagoing out of scope)Sema.rebuild_named_type_candidate_indexSema.rebuild_exact_type_cacheAstPool.Drop.drop,prepare_interface_demand,prepare_body_order,prepare_comptime_eval_copySo the "short-lived maps" were a reading of the exit report, not a fact about the maps: the lookups are in Sema's module-wide tables. 61% of them live until the compilation's own drop at the end of
main(they are freed "before exit" only in the ledger's sense); 28% are the tables of the extraSemarounds that D89 (field types from use) and D93 (literal types from use) run over a module whose decisions change; 5% isrebuild_named_type_candidate_index, rebuilt nine times. The 40,178 small maps carry the remaining 4%.The heaviest single table: a minted 4-byte-key map freed by a round's Sema after 306M lookups, 1520 live of 3569 entries in an 8192 index — a table with heavy remove traffic (tombstones), read 200k times per live entry. Second: a 12,062-entry minted map, 84M–87M lookups in each of two Semas (per-node type table, likely
typed_expr_types).What follows from this is not a hasher or probe change. Two leads, each its own issue: the re-check rounds (a quarter of all lookups re-derive the whole module to hear one decision), and the tombstone-heavy table (which Sema table has ~1500 live entries with constant insert/remove during a check, and whether it wants a stack or an epoch instead of a map).
ehartford commentedon Nov 8, 2026
Answered above: the lookup volume is Sema's module-wide tables (61% the final Semas', 28% the D89/D93 re-check rounds', 5% the type-candidate index rebuilt nine times), not many short-lived maps. The threshold mode that found it lands with the
i3093branch; the two leads are filed as their own issues.#3093: WITH_TRACE_HM_PROBES=<N> reports a map freed after N lookups w…