Repository navigation
Split the router's miss and cascade paths and rename its methods - #3047
Merged
Merged
Conversation
#settle and #neighbours handled two situations, no route matching and a route declining, and told them apart with a `cascaded` flag. That flag was true exactly when a route had matched, so it is replaced by two paths: #after_miss looks for the allowed methods and the ANY routes, #after_cascade tries the siblings and the ANY routes. #halt?, a predicate that closed a body as a side effect, goes with it. The names said something else, so: - `transaction` is `dispatch`: there is no atomicity or rollback in it. - `match?`, `greedy_match?` and `neighbour_match?` return a route, so they are `star_route_for`, `allowed_methods_route_for` and `neighbour_route_for`. - `GreedyRoute` is `AllowedMethodsRoute`: it matches on the path whatever the method, and only ever answers with the methods the path allows. Nothing in the ruby-grape org uses the constant outside this repo. The two lookups that repeated `routes.detect` go through `matched_route`. This is #3044, which merged into #3043's branch after #3043 had already merged, so it never reached master. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ericproulx
force-pushed
the
refactor/router-miss-and-cascade
branch
from
October 31, 2026 17:20
6acb8c0 to
e1b05cd
Compare
Danger ReportNo issues found. |
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.
Replaces #3044, which merged into #3043's branch after #3043 had already merged, so it never reached master. The code is identical to #3044, replayed onto current master.
Summary
No behaviour change.
#settleand#neighbourshandled two situations, no route matching and a route declining, and told them apart with acascadedflag that was true exactly when a route had matched. That flag becomes two paths:#after_misstries the allowed methods (OPTIONS first), the ANY routes, then the 405.#after_cascadetries the siblings, then the ANY routes, and never looks for allowed methods.#halt?, a predicate that closed a body as a side effect, is gone. The two lookups that repeatedroutes.detectnow go through#matched_route.Renames
transaction,bucket_transaction,union_transactiondispatch,dispatch_to_bucket,dispatch_to_unionmatch?(input, '*')star_route_for(input)'*'was its only argumentgreedy_match?allowed_methods_route_forneighbour_match?neighbour_route_forlast_neighbor_routeallowed_methods_routeneighbourRouter::GreedyRouteRouter::AllowedMethodsRouteRouter::GreedyRouteis the only name that isn't private, and it's undocumented and never handed to users. GitHub code search finds it only in this repo across the ruby-grape org, grape-swagger included, so there's no alias and no UPGRADING entry.@neutral_mapand@neighbour_mapkeep their names.Measured
Measured on #3044, against #3043, and not rerun here: one worktree, order alternated each round, 100 CRUD resources plus two header versions.
Throughput is flat. A first 7-round run read −3.9% on POST 405 without JIT and −3.8% on GET with a param under YJIT, so those two were rerun for 9 rounds with an A/A control:
Test plan
cascade: false, no auto-OPTIONS/HEAD, buckets and mounted Rack apps. Status,Allow,X-Cascade, content type and first body line are compared, plusrecognize_path.🤖 Generated with Claude Code