Simon Jakobi pushed to branch wip/sjakobi/cgwork-perf-aggregate at Glasgow Haskell Compiler / GHC Commits: 7de332f3 by Simon Jakobi at 2026-06-30T02:39:04+02:00 cgwork perf-aggregate: record rewriteType2/rewrite_one findings rewriteType2 is the rewrite_one loopbreaker (central rewriter loop); driven by the T9872 family. Body is already optimal; the per-tyvar rebuild (A) and the fam-app FINISH-1 re-walk (B) are levers. Link the TODO note tracking it. Assisted-by: Claude Opus 4.8 - - - - - 8f7b0c8c by Simon Jakobi at 2026-06-30T02:56:04+02:00 cgwork perf-aggregate: record Unify matcher (ruleMatchTyKiX3) findings ruleMatchTyKiX3 is the shared type matcher (unify_ty/tc_unify_tys), not RULE matching; in T9872b it is driven by type-family rewriting. Note the two (A) allocation levers (dead () in the (UMState,()) result pair; CanEqLHS/UMEnv boxing at uVarOrFam call sites) and the (B) re-match hypothesis, with a pointer to the full writeup in ~/ghc/todos. Assisted-by: Claude Opus 4.8 - - - - - fd9f3eef by Simon Jakobi at 2026-06-30T03:06:36+02:00 cgwork perf-aggregate: resolve eq_type_expand_ignore to opt_trans_rule Identity rule Driver T8095 (98.7% of entries); 100% of callers are the last-resort RedTypeDirRefl Identity rule in opt_trans_rule, running a deep eqType (coercionLKind co1 vs coercionRKind co2) per transitivity composition — 745x fanout, returns False >=96% of calls. Full investigation + (B) levers in ~/ghc/todos/opt-trans-rule-identity-eqtype-deep-walk.md. Assisted-by: Claude Opus 4.8 - - - - - 1 changed file: - FINDINGS.md Changes: ===================================== FINDINGS.md ===================================== @@ -116,9 +116,36 @@ deliverable. from `$weqDeBruijnType` + 20.7 % from `splitAppTyNoView_maybe` → the cost is **de Bruijn type-key equality in the solver's TrieMaps**. `rewriteType2` (16.29 %) entered 10.8 % via `TyCon_con`. Cleanly symbolised. -- `eq_type_expand_ignore` (suite #2) is *not* top in any of the five tests - profiled — driven by other type-comparison-heavy tests (candidates: T9872c, - T8095, T13719). One more callgrind run would localise it. +- **`rewriteType2` = `rewrite_one`** (the central rewriter loop) is itself a + T9872b driver: 8 top-level `rewrite` calls (← `can_eq_nc`) explode into 1.98 M + node-rewrites via the fam-app FINISH-1 re-walk. Body already optimal (one-shot + monad, famapp-cache); levers are a cheap per-tyvar rebuild short-circuit (A) and + the hard "don't re-walk already-normal sub-structure" (B). Investigation + + levers: [[rewriteType2-rewrite-one-tyvar-rebuild-and-famapp-rewalk]] in + `~/ghc/todos`. +- **`ruleMatchTyKiX3` (0.59 %, `SCALES`) is the shared type matcher**, not RULE + matching — it is `unify_ty`/`tc_unify_tys` specialized into `ruleMatchTyKiX`. + Driver **T9872b**: 897,764 entries, ~86 MB suite-wide alloc (it is *not* a + 0-alloc walk — it allocates `UM`-monad plumbing). Caller chain + `← tc_unify_tys ← $wtc_match_tys`/`reduceTyFamApp_maybe ← rewriteType2`, i.e. + type-family rewriting again. Two (A) levers (the dead `()` in the + `(UMState,())` result pair; the `CanEqLHS`/`UMEnv` boxing at `uVarOrFam` call + sites — `uVarOrFam` is the #3 suite allocator at 158 MB) plus a (B) re-match + hypothesis shared with the rewriter: + [[unify-matcher-um-monad-pair-and-uvarorfam-boxing]] in `~/ghc/todos`. +- **`eq_type_expand_ignore` (suite #2, 6.81 %) is resolved**: driver **T8095** + (98.7 % of entries — the deep type-family reduction), a 0-alloc structural walk + with the `reallyUnsafePtrEquality#` fast path already present (A done). Late-CCS + pins **100 %** of callers on a single source line: the *last-resort* Identity + rule of `opt_trans_rule` (`Opt.hs:979`, `RedTypeDirRefl`), which runs a full + `eqType (coercionLKind co1) (coercionRKind co2)` at every transitivity + composition. 251 k checks → 187 M node compares (745× fanout, deep common + prefix), and it returns `False` in ≥96 % of calls (mkReflCo entered only 10 k×), + so it's ~O(n·depth) wasted re-walking of near-identical endpoint types. (The + `assertPpr` at `Opt.hs:779` is compiled out in perf builds — not the culprit.) + Investigation + (B) levers (guard the optional check / share endpoint types / + reshape chain optimisation): [[opt-trans-rule-identity-eqtype-deep-walk]] in + `~/ghc/todos`. ### Interface load/write (MultiLayerModules) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/4997934ff66d4ce311a3107b2d1a132... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/4997934ff66d4ce311a3107b2d1a132... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Simon Jakobi (@sjakobi2)