Skip to content

D196 follow-up: measure the probe count of the compiler's maps now that they hash with Minted #3087

Closed

Description

@ehartford

D196 asked, after the src/ Minted sweep (#3084): a third of with check in SipHash over four bytes suggested the maps are probed far more than needed, so the second win may be the probe count. Measure it: instrument hm_find/the probe loop under WITH_DEBUG_ALLOC or a new counter env (WITH_TRACE_HM_PROBES=1, a histogram of probes per lookup by map), run check src/main.w, and read which maps probe most and why (load factor, the mixer, key clustering). The timing so far: unswept 125–177 s vs swept 100–108 s for check src/main.w under load.

Activity

  1. ehartford commented on Nov 8, 2026

    @ehartford
    ContributorAuthor

    Measured with WITH_TRACE_HM_PROBES=1 (the runtime counter this issue's PR adds; out/stage/bin/with-stage2 check src/main.w on a tree at #3084):

    hm-probes: lookups=2617994401 slots=3081095522 slots/lookup=1.17
    hm-probes: slots read per lookup: 1:2325135311 2:206254946 3:46982062 4:18957928 5-8:18864334 9-16:1634917 17-64:162373 65+:2530
    hm-probes: by key kind: bytes 27703499 1.05   str 171588385 1.06   minted 2418702517 1.18
    hm-probes: maps freed before exit (kind maps lookups slots/lookup): bytes 98 27478890 1.05   str 51 20172710 1.36   minted 40178 2364393453 1.18
    

    The top live maps: the 16-byte str map with 106,269 entries (the symbol pool) takes 147M lookups at 1.02 slots; a 4-byte minted map holding 3 entries takes 4.2M; a 12,822-entry minted map 2.4M at 1.31.

    What this says:

    • Probing is not the second win. 89% of lookups read exactly one slot; the mean is 1.17 (minted 1.18, str 1.06). The index is rebuilt at 2/3 load and the mixer spreads sequential IDs; there is no clustering to fix. The 2,530 lookups that read 65+ slots are all in short-lived maps (none of the live top twenty exceeds 2.12).
    • The volume is the cost: 2.6 billion lookups in one check, 26M per second. 90% of them (2.36B) are on 40,178 minted-keyed maps that are created and freed during the check, i.e. per-body or per-instance tables in Sema and MIR, not the module-wide ones. The str symbol pool is the only long-lived map that matters, and it is already at 1.02.
    • So the next measurement is which creation sites make the 40k maps and which lookups on them repeat (a body-local table rebuilt per body, or one lookup per node per pass). The counter cannot name a site from the runtime; the follow-on is a WITH_TRACE_HM_PROBES=2 mode that prints a backtrace at the creation of any map whose lookups exceed a threshold when it is freed, or Sema-side counting at the HashMap.new() sites of check_fn_body_with_sig_once.
  2. added a commit that references this issue on Nov 8, 2026
  3. ehartford commented on Nov 8, 2026

    @ehartford
    ContributorAuthor

    Landed in #3091 (WITH_TRACE_HM_PROBES=1), measurement posted above: probing is at its floor (1.17 slots per lookup); the cost is 2.6 billion lookups, 90% on 40,178 short-lived minted-keyed maps. The creation-site attribution is the next question and gets its own issue.

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