Skip to content

The D89/D93 re-check rounds re-derive a whole module to hear one decision: 28% of the compiler's map lookups on check src/main.w #3099

Closed

Description

@ehartford

From #3093's measurement: of 2.6B map lookups in one check src/main.w, 0.67B are in the tables of Sema instances that Zcu.compile_source_frontend_mode creates for the D89 probe (field numeric types from use) and the D93 literal rounds (collection literal types from use) and drops when the round ends. Each round is a complete check of the module with the previous round's decisions installed.

The question is whether a round has to re-check everything. A decision changes the types of the bindings it names and what flows from them; bodies that mention none of them are unchanged. Options: (a) re-check only the bodies whose decl set intersects the decided bindings (the body-order machinery already knows each body's names); (b) keep the first round's Sema and re-check in place with the decisions applied, instead of a fresh Sema that re-collects every declaration; (c) decide more in the first round (a demand heard early enough is a decision, not a round).

Measure first: WITH_PROFILE=1 already prints per-phase time; add the round count per module and the time per round, then the share of check src/main.w the extra rounds cost.

Activity

  1. ehartford commented on Nov 8, 2026

    @ehartford
    ContributorAuthor

    Measured (branch i3099: the frontend's [profile] frontend.sema line now carries checks=K probe-ms=P literal-rounds=L rounds-ms=R; WITH_PROFILE=1 with-stage1 check src/main.w):

    [profile] frontend.sema  107266 ms  decls=20884  int-local-rechecks=35  checks=2 probe-ms=0 literal-rounds=1 rounds-ms=53336
    

    The compiler is one module of 20,884 declarations, and Sema runs over it twice: the check, then one D93 literal round, and the round is 53.3 s of 107.3 s: half of all Sema time, re-deriving everything to apply the decisions of a handful of let x = []-style bindings whose collection type their uses decided. No D89 probe (no inferred numeric fields in src/).

    Next: list the bindings that force the round (their count and sites), then decide between re-checking only the bodies that mention them and deciding them in the first pass; either removes about 40% of check src/main.w.

  2. ehartford commented on Nov 8, 2026

    @ehartford
    ContributorAuthor

    The bindings that force the second pass over the compiler (the profile now lists them as [profile] literal-demand): 17, all locals of the form let xs = [] whose element type the first push a few lines later decides:

    src/Parser.w:5474 until_syms → List[i32]            src/ForeignPairState.w:237/253/386/388/410 (5)
    src/CodegenDispatch.w:12716 at → List[i64]          src/SemaDecl.w:1357/1476 owners → List[i32]
    src/SemaCheck.w:2465/2576/2867 (3) → List[i32]      src/CeremonyFix.w:99/205/228/241/305 (5)
    

    Seventeen body-local decisions, each visible within its own body, and the price is one more Sema pass over 20,884 declarations: 53 s. Annotating them would buy the time back today, at the cost of the census's list-annotation count and of writing what the compiler knows (two of the 17 are from this week's sweeps dropping exactly such annotations). The fix in the compiler is to re-check only the body that holds the decided binding: int-local-rechecks=35 on the same line says a per-body re-check already exists for D126's int locals, so the literal decision takes the same route and the module-wide round goes.

  3. ehartford commented on Nov 8, 2026

    @ehartford
    ContributorAuthor

    Fixed on branch i3099: a body's settle loop (the one D126's int locals already use) takes the literal demands its pass recorded, makes them body decisions, drops the pass's diagnostics and checks the body again at the decided types; a binding two typed uses disagree about still goes to the module round for its error. Measured on check src/main.w:

    before: checks=2  frontend.sema 107266 ms  (literal round 53336 ms)
    after:  checks=1  frontend.sema  53930 ms
    

    The 134 literal-typing fixtures pass (including err_d93_two_demands, which the first version lost by deciding the second demand alone), plus a new fixture for three in-body shapes. Gate running; battery next.

  4. added 3 commits that reference 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