Skip to content

perf: defer extractor error-path tracking until failure - #591

Open
robjtede wants to merge 3 commits into
mainfrom
perf/defer-extractor-error-paths
Open

robjtede wants to merge 3 commits into
mainfrom
perf/defer-extractor-error-paths

Conversation

@robjtede

@robjtede robjtede commented Nov 7, 2026

Copy link
Copy Markdown
Member

Successful JSON, query, and form extraction currently pays for field-path tracking. Deserialize without tracking first, then retry over the same buffered input with serde_path_to_error only on failure. This follows tokio-rs/axum#3924 (commit 853067671a38632ceab12cc6227c046152db779c).

JSON keeps its current trailing-input behavior; this does not add an end-of-input check. Body limits, content-type checks, parser choice, and detailed error mapping remain unchanged. The deser-based extractors are unchanged.

Custom deserializers can run twice, repeat side effects, or produce a different result. A successful retry is accepted. The extractor docs state this behavior, and a test covers a stateful deserializer that succeeds on retry.

Local benchmark results

Extractor operation-rate changes with 95% paired bootstrap intervals

Case Before ns/op After ns/op Operation-rate change 95% paired interval
query-success 327.3 180.5 81.27% 79.50% to 82.96%
query-early 420.3 621.9 -32.42% -33.02% to -31.75%
query-late 619.8 912.4 -32.07% -32.90% to -31.18%
json-success 890.5 742.4 19.94% 18.82% to 21.08%
json-early 1056.8 1249.0 -15.39% -15.89% to -14.88%
json-late 1179.4 1422.2 -17.06% -17.85% to -16.19%
form-success 1061.2 918.2 15.57% 14.23% to 17.14%
form-early 1139.5 1367.8 -16.69% -17.30% to -16.04%
form-late 1335.6 1658.4 -19.46% -20.43% to -18.33%

Eight alternating paired rounds, each with 1 s warmup and 1 s measurement; release builds with the same compiler and lockfile. Rust 1.100.0-beta.7 on macOS. No CodSpeed or sockets.

Payload: { n: u32, s: String, b: bool }. Early and late failures are invalid values in the first and last fields of a small payload. Query measures from_query; JSON/form include request construction, buffering, and extraction. All cases check the result; errors are formatted. These are not full HTTP throughput measurements, and absolute times are not comparable across extractor types.

The result is a success/failure tradeoff: valid inputs improve; invalid inputs cost more. Bootstrap intervals describe this local session. Compiler layout and machine noise remain possible. The tested baseline is 5d2189d and predates current upstream main; the results are not from a refreshed upstream build. Existing unrelated russe edits were identical in both benchmark builds and are excluded from this PR.

Method and reproduction steps · Raw samples · Summary

Validation

  • cargo test -p actix-web-lab --lib --test extractor_error_paths --locked --quiet: 147 unit tests and 4 integration tests passed.
  • just clippy: workspace, all targets, all features; passed without warnings.
  • Changed Rust files formatted with nightly rustfmt and the workspace config.

Regression coverage includes diagnostic paths/messages, JSON error classification, existing body limits, trailing JSON, and successful retry of a custom deserializer.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant