ReviewOS

home-lang/home

perf(ts-checker): eliminate redundant typed identifier fallback scans

#419
Closed chris opened this 8 days ago ·
8 days ago

Context

The accepted control_flow workload on the TypeScript comparison tracker uses one unchanged 9,485-line module with 256 discriminated-union switches, narrowed property reads, definite assignments, exhaustiveness checks, and typed return objects. All three compilers accept it silently.

Five-run red baseline (milliseconds):

CompilerMeanStddev
tsc 6.0.3281.952.8
TypeScript 7.0.2 native81.521.8
Home2927.8159.6

Profile

An Xcode Time Profiler capture over the unchanged workload attributes most execution time to repeated whole-source compatibility fallbacks reached from typed identifier lookup:

  • ~48% inclusive in typeAnnotationContainsUnresolvedRef, with repeated UMD namespace discovery/source scans
  • ~40% inclusive in recoveredSourceParameterAnnotationType / sourceParameterDeclarationContainsUse, even when a lexical HIR annotation was already found
  • ~10% in used-before-assignment scans, to reassess after removing the dominant redundant work

The checker already computes source_may_have_umd_namespace_export in setSource, but sourceHasUmdNamespaceExport does not consult it. Parameter syntax recovery is likewise intended as a parser-recovery fallback and should not rescan when the lexical annotation is present.

Acceptance criteria

  • Keep the committed benchmark source, size, and compiler configurations unchanged.
  • Skip parameter recovery only when the normal lexical annotation is available.
  • Use the conservative UMD prefilter without changing UMD behavior.
  • Run focused compatibility tests and the complete TypeScript checker suite.
  • Re-profile and address any remaining general bottleneck required for Home to beat TypeScript 7.0.2 on this workload.
  • Publish the corrected 30-run result in the performance docs and README summary.

Refs #416

8 days ago

Completed against the unchanged accepted workload.

Landed commits:

  • 0f57b848f — prune impossible checker compatibility scans and reuse resolved binding types
  • a7e75e18b — skip impossible program-level source collectors
  • 9c6c03f11 — prune absent import/class/enum/CommonJS lookups and reuse the declaration index
  • 2a460f5b3 — publish the detailed result and README summary

Validation:

  • focused UMD, parameter recovery, annotations, control-flow, imports, CommonJS, namespaces, class/enum, and expando tests passed
  • complete ts_program suite passed
  • complete 4,190-test ts_checker suite passed after the first optimization set and again after the final lookup pruning
  • Zig formatting, git diff --check, and Pickier completed with no errors (one unrelated pre-existing README fragment warning remains)

Final 30-run result after three warmups (20260826T221047Z):

Workloadtsc 6.0.3native TS 7.0.2HomeHome result
control_flow203.8 ± 73.2 ms62.7 ± 16.1 ms55.5 ± 11.3 ms1.13x faster

The five-run red baseline was Home 2,927.8 ± 159.6 ms versus native TS 7 at 81.5 ± 21.8 ms. The unchanged workload is now 52.8x faster in Home and wins against both competitors. The accepted suite is 8/8 Home wins.

Sign in to comment on this issue.