PerlDancer / PerlDancer/Dancer2
Request::new eagerly parses the body on every request, including GETs
Nobody has claimed this yet.
- Dominant language
- Perl
- Stars
- 604
- Forks
- 288
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 5
Description
Status: reasoned from code · This is the highest-risk change of the three performance items — do not bundle it with unrelated fixes.
lib/Dancer2/Core/Request.pm:91-92:
# Deserialize/parse body for HMV
$self->data;
$self->_build_uploads();
Both are eager, and _build_uploads calls $self->_body_params (line 584), which forces full body parsing. Every request pays for this even when the route never touches params or uploads — including every GET.
This is the largest of the three performance items identified in the sweep. Making it lazy would skip body parsing entirely on the common read path.
Implementation warning
Do not simply make uploads lazy. _build_uploads has a side effect — lines 600-603 write upload filenames back into _body_params so they are reachable as ordinary params:
# support access to the filename as a normal param
my @filenames = map $_->{'filename'}, @uploads;
$self->{_body_params}{$name} = @filenames > 1 ? \@filenames : $filenames[0];
So the laziness has to be anchored on _body_params (and params), not on uploads alone — otherwise that documented behaviour silently breaks depending on whether anything happened to touch uploads first.
Suggested approach: have _body_params trigger upload building, guarded by a _uploads_built flag, and have uploads do the same. Both entry points then converge on one idempotent builder.
_shallow_clone (line 639) also constructs a request with body_params => {} and then overwrites several of these slots directly — check it still behaves once construction no longer eagerly populates them.
Needs care and a thorough test pass.
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/Request.pm at lines 91-92, then trace _body_params, params, _build_uploads, uploads, and _shallow_clone. Run the existing Request tests and verify that GET requests avoid eager body parsing while filename parameters, uploads, and shallow clones retain their documented behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- perl
- Domain
- backend, performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100