Skip to content

perf: speed up route validator scanning - #108

Open
RomainLanz wants to merge 1 commit into
8.xfrom
perf/speed-up-route-scanning
Open

perf: speed up route validator scanning#108
RomainLanz wants to merge 1 commit into
8.xfrom
perf/speed-up-route-scanning

Conversation

@RomainLanz

@RomainLanz RomainLanz commented Sep 1, 2026

Copy link
Copy Markdown
Member

Hey! 👋

Route validator scanning currently builds six ast-grep patterns for every controller method it inspects. This repeated pattern construction becomes a visible CPU cost as the route count grows.

This PR traverses call expressions once and compares their function references directly. It preserves the existing $CTX receiver behavior, ignores comments inside member expressions, and does not introduce optional chaining matches that the previous ast-grep patterns rejected.

Focused tests cover comments, nested calls, tryValidateUsing, $CTX, VineJS calls, member references, optional chaining, and direct validator usage.

Benchmark

Node.js 24.20.0 using the public RoutesScanner.scan API. The fixture uses five actions per controller and distributes the six supported validation syntaxes across routes.

Each variant ran in 4 independent processes with 2 warmups and 15 measured scans per process. Execution order alternated between variants and GC ran before every measurement.

Routes Before After Change
50 27.01 ms 22.56 ms -16.5%
125 60.60 ms 50.53 ms -16.6%
250 120.36 ms 95.11 ms -21.0%
500 242.02 ms 193.48 ms -20.1%

At 500 routes, the change saves 48.54 ms per complete scan.

Across ten 500-route scans, the CPU profile dropped from 3,330 to 2,503 samples. Samples attributed directly to inspectMethodArguments dropped from 835 to 85.

Validation

  • 267 tests passed on Node.js 24
  • Typecheck passed
  • ESLint passed
  • git diff --check passed

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.

1 participant