Skip to content

Commit 6fd05c9

Browse files
committed
Stop eagerly computing request.route_uri_pattern
This was introduced in rails#47129 by GitHub folks because they need the route pattern in HTML for some reason. But the overwhelming majority of applications don't need that information, so there is no point wasting time precomputing it. Followup: rails#54504 Followup: rails#54491 Same benchmark as: rails#54491 (comment) ``` == index == ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +PRISM [arm64-darwin23] Warming up -------------------------------------- after 46.519k i/100ms Calculating ------------------------------------- after 468.807k (± 0.5%) i/s (2.13 μs/i) - 2.372M in 5.060781s Comparison: before: 363898.7 i/s after: 468807.2 i/s - 1.29x faster == show == ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +PRISM [arm64-darwin23] Warming up -------------------------------------- after 36.443k i/100ms Calculating ------------------------------------- after 363.585k (± 0.6%) i/s (2.75 μs/i) - 1.822M in 5.011832s Comparison: before: 276473.5 i/s after: 363584.9 i/s - 1.32x faster == show_nested == ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +PRISM [arm64-darwin23] Warming up -------------------------------------- after 33.943k i/100ms Calculating ------------------------------------- after 339.724k (± 0.2%) i/s (2.94 μs/i) - 1.731M in 5.095599s Comparison: before: 246010.1 i/s after: 339724.5 i/s - 1.38x faster ```
1 parent 0209bf4 commit 6fd05c9

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

actionpack/lib/action_dispatch/http/request.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,16 @@ def request_method
157157
#
158158
# request.route_uri_pattern # => "/:controller(/:action(/:id))(.:format)"
159159
def route_uri_pattern
160-
get_header("action_dispatch.route_uri_pattern")
160+
unless pattern = get_header("action_dispatch.route_uri_pattern")
161+
route = get_header("action_dispatch.route")
162+
pattern = route.path.spec.to_s
163+
set_header("action_dispatch.route_uri_pattern", pattern)
164+
end
165+
pattern
161166
end
162167

163-
def route_uri_pattern=(pattern) # :nodoc:
164-
set_header("action_dispatch.route_uri_pattern", pattern)
168+
def route=(route) # :nodoc:
169+
set_header("action_dispatch.route", route)
165170
end
166171

167172
def routes # :nodoc:

actionpack/lib/action_dispatch/journey/router.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def serve(req)
4343
}
4444

4545
req.path_parameters = tmp_params
46-
req.route_uri_pattern = route.path.spec.to_s
46+
req.route = route
4747

4848
_, headers, _ = response = route.app.serve(req)
4949

0 commit comments

Comments
 (0)