PerlDancer / PerlDancer/Dancer2

Request::new eagerly parses the body on every request, including GETs

Open
#1,818 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.