Skip to content

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

Closed

Description

@ehartford

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:

  1. 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).
  2. 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.

Activity

  1. ehartford commented on Nov 8, 2026

    @ehartford
    ContributorAuthor

    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) 35 0.67B
    Sema.rebuild_named_type_candidate_index 9 0.11B
    Sema.rebuild_exact_type_cache 4 0.03B
    AstPool.Drop.drop, prepare_interface_demand, prepare_body_order, prepare_comptime_eval_copy 13 0.02B

    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).

  2. ehartford commented on Nov 8, 2026

    @ehartford
    ContributorAuthor

    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.

  3. added a commit that references this issue on Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions