Skip to content

Zero-Copy Body Conversion and Performance Benchmarks#627

Merged
bnusunny merged 4 commits into
mainfrom
zero-copy-body-conversion
Jan 23, 2026
Merged

Zero-Copy Body Conversion and Performance Benchmarks#627
bnusunny merged 4 commits into
mainfrom
zero-copy-body-conversion

Conversation

@bnusunny

Copy link
Copy Markdown
Contributor

This PR optimizes the body forwarding path in the Lambda Web Adapter by eliminating unnecessary memory copies, and adds comprehensive benchmarks with CI integration to prevent performance regressions.

Description of changes:

Zero-Copy Body Conversion
Replaced body.to_vec() in fetch_response() with a match expression that moves ownership instead of copying:

Performance Benchmarks

  • Added e2e_body_forwarding.rs with end-to-end benchmarks
  • Tests text and binary bodies from 0 to 6MB (Lambda payload limit)
  • Uses httpmock for realistic HTTP round-trip testing
  • Binary body sizes correctly account for base64 encoding overhead

CI Workflow

  • Added benchmark.yaml to run benchmarks on PRs
  • Compares PR branch against main using critcmp
  • Fails the check if any benchmark regresses more than 10%
  • Posts benchmark results as a PR comment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

- Replace body.to_vec() with match expression that moves ownership
  of underlying data instead of copying
- Body::Text uses into_bytes() to consume the String
- Body::Binary moves the Vec directly
- Add fallback for future non-exhaustive Body variants

- Add with_binary_body() to LambdaEventBuilder for proper binary
  body testing with base64 encoding
- Add test_http_request_body_forwarded integration test covering
  all three Body variants (Empty, Text, Binary)
- Add e2e_body_forwarding benchmark testing text and binary bodies
  from 0 to 6MB (Lambda payload limit)
- Add GitHub Actions workflow to run benchmarks on PRs and detect
  regressions >10%
- Add criterion and critcmp for benchmark comparison
- Benchmark uses httpmock for realistic HTTP round-trip testing
- Binary body sizes account for base64 encoding overhead
@bnusunny

Copy link
Copy Markdown
Contributor Author

The benchmark workflow failed because the main branch does not have the benchmark code until this PR is merged.

@bnusunny bnusunny merged commit c23f098 into main Jan 23, 2026
25 of 26 checks passed
@bnusunny bnusunny deleted the zero-copy-body-conversion branch January 23, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants