Skip to content

perf(aws-lambda)!: read event headers once when parsing the body, remove getEventHeader - #132

Merged
dinwwwh merged 1 commit into
mainfrom
claude/aws-lambda-header-rereads-f5163c
Sep 29, 2026
Merged

dinwwwh merged 1 commit into
mainfrom
claude/aws-lambda-header-rereads-f5163c

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Sep 29, 2026

Copy link
Copy Markdown
Member

toStandardBody in the aws-lambda adapter now reads each Lambda event's headers once, instead of scanning every header key six times. Body parsing's header work is about 1.5–1.7x faster on a typical 20-header event. getEventHeader, which nothing used any more, is removed from the public API.

Performance

20-header event, body header reads before after
payload format 1.0 ~10 µs ~6.5 µs
payload format 2.0 ~7 µs ~4.1 µs

Breaking change

getEventHeader is no longer exported from @standard-server/aws-lambda. Replace it with toStandardHeaders(event)[key.toLowerCase()]. The result differs in two edge cases: a single-value 1.0 multiValueHeaders entry comes back as a string instead of a one-item array, and 1.0 header keys that differ only in case are merged instead of first-match.

Testing

  • Body parsing is now tested with 1.0 events that carry headers only in headers, and with 2.0 events.
  • The one rule that was only tested through getEventHeader (a cookie header takes priority over the 2.0 cookies field) is now tested on toStandardHeaders. headers.ts stays at 100% coverage.
  • aws-lambda tests (98 passed), eslint, and the repo-wide typecheck are clean.

…ove `getEventHeader`

`toStandardBody` called `getEventHeader` six times, and every call
lowercased and scanned every header key (both `multiValueHeaders` and
`headers` on payload format 1.0). It now builds the header map once with
`toStandardHeaders` and reads each header from it, about 1.5-1.7x faster
on a 20-header event.

`getEventHeader` had no remaining callers and repeated the merge rules of
`toStandardHeaders` with slightly different results, so it is removed.

BREAKING CHANGE: `getEventHeader` is no longer exported from
`@standard-server/aws-lambda`. Use `toStandardHeaders(event)[key.toLowerCase()]`.

Co-Authored-By: Claude <noreply@anthropic.com>
@pkg-pr-new

pkg-pr-new Bot commented Sep 29, 2026

Copy link
Copy Markdown
@standard-server/aws-lambda

npm i https://pkg.pr.new/@standard-server/aws-lambda@132

@standard-server/core

npm i https://pkg.pr.new/@standard-server/core@132

@standard-server/fastify

npm i https://pkg.pr.new/@standard-server/fastify@132

@standard-server/fetch

npm i https://pkg.pr.new/@standard-server/fetch@132

@standard-server/node

npm i https://pkg.pr.new/@standard-server/node@132

@standard-server/peer

npm i https://pkg.pr.new/@standard-server/peer@132

@standard-server/shared

npm i https://pkg.pr.new/@standard-server/shared@132

commit: 3074b24

@codecov

codecov Bot commented Sep 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 26 untouched benchmarks
⏩ 108 skipped benchmarks1


Comparing claude/aws-lambda-header-rereads-f5163c (3074b24) with main (7d2294c)

Open in CodSpeed

Footnotes

  1. 108 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Read event headers once — toStandardBody replaces four getEventHeader scans with a single toStandardHeaders(event) and derives the body hint plus content-type / content-disposition from it (packages/aws-lambda/src/body.ts:23).
  • getEventHeader removed — the export and its five tests are gone; the cookie-over-cookies priority it uniquely covered is re-tested on toStandardHeaders (packages/aws-lambda/src/headers.ts, headers.test.ts).
  • Fallback coverage — toStandardBody is now exercised with a v1 event whose content headers live only in headers and with a v2 event (body.test.ts).
  • README drops getEventHeader from the lower-level helpers row.

The refactor is behavior-preserving for body parsing: single multi-value reads normalize identically through flattenStandardHeader, multiValueHeaders still wins per key, and both implementations skip empty/undefined values. The two documented divergences (single-value 1.0 entries as string not [string], case-variant 1.0 keys merging) only affect external getEventHeader callers or pathological events, and are called out in the PR description. Verified locally at this head: vitest run packages/aws-lambda → 98 passed, repo type:check clean, eslint clean.

Pullfrog  | View workflow run | Using DeepSeek Flash (default — pick a model for stronger reviews) | 𝕏

@dinwwwh
dinwwwh merged commit 75cffb5 into main Sep 29, 2026
11 checks passed
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.

1 participant