PerlDancer / PerlDancer/Dancer2
Route::match re-parses the route regexp on every successful match
Nobody has claimed this yet.
- Dominant language
- Perl
- Stars
- 604
- Forks
- 288
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 5
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/Dancer2/Core/Route.pm at match around lines 111-112, then read BUILDARGS around line 237 and _build_regexp_from_string around line 244 to follow how route metadata is constructed. Benchmark the current and updated matching paths before and after; done means match uses the precomputed token ordering without rescanning the regexp.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- perl
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100