Skip to content

perf(router): try templates with an index loop - #452

Merged
dinwwwh merged 1 commit into
mainfrom
claude/project-thread-4zwssp
Nov 29, 2026
Merged

dinwwwh merged 1 commit into
mainfrom
claude/project-thread-4zwssp

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Nov 29, 2026

Copy link
Copy Markdown
Member

🤖 Generated with Claude Code

https://claude.ai/code/session_01VVaw7NfvMWthzxzRb81nfW

What

findTemplate destructured each template child in a for...of loop and read segments[index] on every pass. It now reads the children by index, the way find already reads catch-alls, and reads the segment once.

Cost (vs main 78a428a)

  • min+gzip: 2,529 → 2,527 B (-2).

  • Steady instructions per match (callgrind, hash seeds 1 and 2, the 500-route template set from perf(router): check templates without slicing the value #451):

    Case Before After Change
    template hit 3,265 3,251 -0.4%
    template miss, then param 3,205 3,155 -1.6%
    v{v} hit, after the other templates miss 3,608 3,544 -1.8%
  • Cold start (cold3, callgrind) on rpc10, rest10 and tpl10 is within ±0.2%.

Checks

  • Router tests pass with 100% coverage, and tsc and oxlint are clean.
  • The template fuzzer (seeds 11-13) and the README-model edge fuzzer (seeds 11-13) found 0 diffs.

Generated by Claude Code

for...of destructuring each template child costs more than reading it by
index, as find already does for catch-alls, and the segment is read once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VVaw7NfvMWthzxzRb81nfW
@dinwwwh dinwwwh self-assigned this Nov 29, 2026
@coderabbitai

coderabbitai Bot commented Nov 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 41 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ccfdf8fb-c966-47b1-8aa8-657e785f770f
Commits

Reviewing files that changed from the base of the PR and between 78a428a and 46f0fe2.

Files selected for processing: 1

  • packages/router/src/index.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@pkg-pr-new

pkg-pr-new Bot commented Nov 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@openapi-spec/downgrader@452
npm i https://pkg.pr.new/@openapi-spec/router@452
npm i https://pkg.pr.new/@openapi-spec/types@452

commit: 46f0fe2

@codecov

codecov Bot commented Nov 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Approach: sound — a behavior-preserving micro-optimization that matches the existing catchAlls index-loop pattern in find.

Reviewed changes

  • findTemplate index loop — replaces the for...of + destructuring with an index loop and hoists const segment = segments[index]! out of it, so matchesTemplate and find read templates[i]! directly.
  • Semantics — iteration order and per-element work are unchanged; segments is not mutated during matching and node.templates is only appended to during insertion, so the hoisted segment and live array reads cannot diverge from the old behavior.
  • Tests — pnpm vitest run packages/router passes (7 files, 75 tests), including templates.test.ts.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@codspeed

codspeed Bot commented Nov 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 33 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing claude/project-thread-4zwssp (46f0fe2) with main (78a428a)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@dinwwwh
dinwwwh merged commit ace056a into main Nov 29, 2026
12 checks 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.

2 participants