perf: skip canonicalization via h3's isCanonicalPath fast path - #6
Closed
pi0x wants to merge 1 commit into
Closed
Conversation
For the common already-canonical pathname, the matcher and isPathInScope paid four string scans per request proving canonicalization is a no-op (resolveDotSegments' internal guard + the SEPARATOR_RUN_RE collapse). h3 >= 2.0.1-rc.26 exports its resolver's fast-path guard as `isCanonicalPath`; strict mode (decodeSlashes + mergeSlashes) implies both readings are no-ops, so one h3-owned scan now skips canonicalPath AND mergedCanonicalPath — without this package duplicating any knowledge of what h3 decodes. Safety chain: h3 pins the predicate as exact resolveDotSegments identity; test/scope.test.ts pins the derivation layered on top (strict-mode canonical => canonicalPath identity AND mergedCanonicalPath undefined; seeded fuzz, both directions). Documented in .agents/SECURITY.md. Compiled basicAuth matcher, normal (non-matching, canonical) request: 183ns -> 109ns per match on the same h3 build (210ns on rc.25); matching requests 563ns -> 530ns. Identical results on the adversarial path matrix. Requires h3 2.0.1-rc.26 (h3js/h3#1460, stacked on h3js/h3#1458) — peer and dev pins bumped; blocked on that release. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Member
|
landed on main |
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.
Important
Draft — blocked on h3 releasing
isCanonicalPath(h3js/h3#1460, stacked on h3js/h3#1458). Peer/dev pins are set to the anticipated^2.0.1-rc.26; CI cannot install until it ships. Local verification below ran against apnpm linked build of that branch.What
For the common already-canonical pathname, the matcher and
isPathInScopepaid four per-request string scans proving canonicalization is a no-op (resolveDotSegments' internal guard ×3 + theSEPARATOR_RUN_REcollapse). This adds anisTriviallyCanonicalfast path: h3's newisCanonicalPath(pathname, { decodeSlashes: true, mergeSlashes: true })in strict mode implies both alternate readings are no-ops (canonicalPathidentity andmergedCanonicalPath === undefined), so one h3-owned scan skips them entirely — for the runtime matcher, compiled matchers (createMatcherFromFindis shared), andisPathInScope.No decode knowledge is duplicated in this package — that's the point of upstreaming the predicate: a stale local prescan would silently skip a canonicalization step (an auth/scope bypass, not a perf bug).
Safety chain
isCanonicalPath(p, o)⇔resolveDotSegments(p, o) === p(200k-assertion property test in h3's suite).test/scope.test.tspins the derivation layered on top: strict-mode canonical ⇒canonicalPath(p) === pandmergedCanonicalPath(p) === undefined(seeded fuzz, both directions), plus directed accept/reject cases..agents/SECURITY.md.Numbers
Compiled basicAuth matcher (mitata, node 24, x64), identical results on the adversarial path matrix:
/admin/panel🤖 Generated with Claude Code