Skip to content

refactor(react): enforce shared scope analysis in helpers - #2165

Merged
elecmonkey merged 2 commits into
mainfrom
perf/react-scope-provider
Sep 16, 2026
Merged

elecmonkey merged 2 commits into
mainfrom
perf/react-scope-provider

Conversation

@elecmonkey

Copy link
Copy Markdown
Member

Motivation

React helpers that need lexical scope analysis currently construct scope graphs internally when no TypeChecker is available. This bypasses the shared file-level cache and allows multiple helpers and rules to rebuild the same graph.

Changes

  • Require scope-dependent React helpers to receive a scopeanalysis.Provider from the rule's RuleContext.
  • Make scopeanalysis the only entry point for constructing scope graphs in rule code.
  • Remove uncached compatibility paths from the React helpers.
  • Update the rule-porting guidance and add an architecture test preventing direct scope.Build calls outside scopeanalysis.

A synthetic source-only benchmark ran eight affected React rules through the real linter. Program construction was excluded, and every iteration received a fresh file cache. Results are medians of five runs.

Fixture Time B/op allocs/op
6 components, 12 bare React calls 990 us -> 79.8 us (-91.9%) 1,926,238 -> 75,355 (-96.1%) 25,055 -> 1,139 (-95.5%)
40 components, 80 bare React calls 33.38 ms -> 481 us (-98.6%) 66,011,005 -> 396,347 (-99.4%) 814,868 -> 5,712 (-99.3%)

These fixtures exercise the no-TypeChecker fallback for bare memo, forwardRef, and createElement imports. Existing repository fixtures do not exercise this path densely enough to show a measurable change.

@elecmonkey
elecmonkey added this pull request to stack #2166 September 15, 2026 08:54
Base automatically changed from perf/shared-file-scope-cache to main September 16, 2026 04:13
@fansenze
fansenze force-pushed the perf/react-scope-provider branch from 782a4a0 to 2576612 Compare September 16, 2026 04:13
@elecmonkey
elecmonkey force-pushed the perf/react-scope-provider branch from 2576612 to e980f8a Compare September 16, 2026 10:33
@elecmonkey
elecmonkey marked this pull request as ready for review September 16, 2026 10:34
@elecmonkey
elecmonkey merged commit c26be88 into main Sep 16, 2026
48 of 54 checks passed
@elecmonkey
elecmonkey deleted the perf/react-scope-provider branch September 16, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants