perf: optimize hot path performance in request handling#485
Merged
Conversation
v1rtl
commented
Feb 1, 2026
Member
- Pre-compile regex at middleware registration time instead of lazily on first request
- Replace object spread with Object.assign for params merging to avoid allocations
- Use arrow functions instead of .bind() for fresh/stale getters
- Make stale property a lazy getter instead of eagerly evaluating
- Remove duplicate host string indexOf check
a456500 to
8fdab14
Compare
- Pre-compile regex at middleware registration time instead of lazily on first request - Replace object spread with Object.assign for params merging to avoid allocations - Use arrow functions instead of .bind() for fresh/stale getters - Make stale property a lazy getter instead of eagerly evaluating - Remove duplicate host string indexOf check Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Extract HEAD handler middleware to shared module-level constant - Inline method/exclusion filtering into #find() to avoid intermediate array - Remove currying from handle() to avoid creating new function per middleware call Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds a test verifying that middleware is only executed once even when it would match the URL multiple times during request processing. This exercises the exclude.includes(m) branch in the #find() method. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds a test that calls multiple accepts methods (accepts, acceptsEncodings, acceptsCharsets, acceptsLanguages) on the same request to exercise the lazy caching branch in getAcceptsInstance(). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add tests for precompiled regex usage, static routes with false keys, and wildcard key normalization to improve router branch coverage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
e97639f to
1ab0ca1
Compare
- Add c8 ignore comment for ?? operator branch that V8 coverage doesn't track correctly despite being tested - Remove hardcoded port 3000 in app.test.ts to prevent "Address in use" errors when port is occupied Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.