Find an operation without walking the document - #123
Merged
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: Warning Your free Security trial is over. An organization admin can upgrade to Advanced for continuous pull request security review or dismiss this notice. 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 |
Matching scanned every operation and every one of its servers on every request: a thousand-operation document cost 0.83 ms per validated message, the same for a hit as for a miss, because nothing stopped early. Routes are now bucketed by method, by segment count and by first literal segment — each one a property `matchPath()` checks before anything else, so a bucket miss skips exactly the work that would have been thrown away. Selection cannot change: candidates are ordered by a comparator that ends on the operation key, keys are unique, so the winner never depended on the order they were collected in. Routes whose first segment is templated sit in an always-scanned bucket, and a literal one is compared in its decoded form, which is the form matching compares. A thousand operations went from 0.83 ms to 0.006 ms per request, and the cost no longer grows with the document. The benchmark pins it against the lookup a consumer would write by hand over `operations()`. Two examples join the package: the shape a PSR-15 middleware takes over a multi-file document, and what the budgets on `Limits` do.
rasuvaeff
force-pushed
the
perf/index-operations-for-matching
branch
from
September 6, 2026 17:02
48665bb to
c23c0c7
Compare
Merged
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.
Class C of the full-cycle review (
docs/reviews/review-openapi-contract-2026-09-06-full-cycle.md), findings C-1 and C-2.C-1. Matching scanned every operation and every one of its servers per request — 0.83 ms on a thousand-operation document, identical for a hit and for a miss, since nothing stopped early.
Routes are bucketed by method, segment count and first literal segment. Each key is a property
matchPath()checks before anything else — equal segment counts, a literal equal to the decoded request segment — so a bucket miss skips work that would have been discarded anyway. Templated first segments sit in an always-scanned bucket.Selection is unchanged by construction, not by hope: candidates are sorted by a comparator ending on the unique operation key, so the outcome never depended on collection order. The first attempt bucketed by method and segment count only and came out slower — a document where every path has the same shape lands in one bucket and pays the index for nothing. That measurement is what led to the first-segment key.
A benchmark pins the property against the lookup a consumer would write by hand over
operations(): 1.63 µs versus 225 µs on the same document. A new test pins the bucketing edges — templated first segment, percent-encoded literal, a server base that prefixes the route.C-2.
examples/had one script for thirteen public types. Two more:gate-a-request.php(validate in, hand on, validate out — the shape a PSR-15 middleware takes, over a multi-filefromFile()document) andbudgets.php(Limits, and why*.body.too_largeis a refusal to read).Verification:
composer build,composer rector,bin/package-auditgreen; corpus current (290 cases); mutation 2222 killed / 160 escaped, MSI 93% against a gate of 92 — the two new escapes widen bucketing, which cannot change a verdict, and are classified inAGENTS.md.