Status: confirmed and benchmarked
lib/Dancer2/Core/Route.pm:111-112:
my @token_or_splat =
$self->regexp =~ /\(\?#((?:typed_)?token|(?:mega)?splat)\)/g;
The token/splat ordering is recovered by stringifying the compiled route regexp and scanning it for (?#...) comments — on every successful match.
Benchmark
re-scan regexp each match: 769,231/s (~1.3us)
use precomputed arrayref: 2,000,000/s (~0.5us)
Honest framing
~0.8us per matched route is small next to a full request, so this is tidy-up rather than a meaningful win. It is worth doing only because it is nearly free: _build_regexp_from_string (line 244) already computes this ordering at construction time to populate _params and _typed_params.
Suggested fix
Add a fourth slot to what _build_regexp_from_string returns, alongside _params / _typed_params / _should_capture — e.g. _token_order as an ArrayRef — and read it in match instead of scanning. See BUILDARGS at line 237 for the destructuring that needs extending.
Benchmark before and after rather than taking the above on faith.
Status: confirmed and benchmarked
lib/Dancer2/Core/Route.pm:111-112:The token/splat ordering is recovered by stringifying the compiled route regexp and scanning it for
(?#...)comments — on every successful match.Benchmark
Honest framing
~0.8us per matched route is small next to a full request, so this is tidy-up rather than a meaningful win. It is worth doing only because it is nearly free:
_build_regexp_from_string(line 244) already computes this ordering at construction time to populate_paramsand_typed_params.Suggested fix
Add a fourth slot to what
_build_regexp_from_stringreturns, alongside_params/_typed_params/_should_capture— e.g._token_orderas anArrayRef— and read it inmatchinstead of scanning. SeeBUILDARGSat line 237 for the destructuring that needs extending.Benchmark before and after rather than taking the above on faith.