Skip to content

perf: cache fiber request headers to reduce allocations#2181

Merged
nimrod-teich merged 2 commits into
mainfrom
perf/cache-fiber-headers
Jan 19, 2026
Merged

perf: cache fiber request headers to reduce allocations#2181
nimrod-teich merged 2 commits into
mainfrom
perf/cache-fiber-headers

Conversation

@nimrod-teich

@nimrod-teich nimrod-teich commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

Cache header values at the start of request processing in chain listeners
instead of accessing them multiple times via fiber.(*Ctx).GetReqHeaders
and fiber.(*Ctx).Get().

  • Add GetHeaderFromCachedMap helper for extracting headers from cached map
  • Add ExtractWantedHeadersFromCachedMap to extract context headers from cached map
  • Update jsonRPC, rest, and tendermintRPC handlers to cache headers early
  • Fix redundant fiberCtx.Get() call in rest.go handlerUse

This reduces per-request allocations by consolidating multiple header
access calls into a single GetReqHeaders() call with map lookups.

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • read the contribution guide
  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the main branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Cache header values at the start of request processing in chain listeners
instead of accessing them multiple times via fiber.(*Ctx).GetReqHeaders
and fiber.(*Ctx).Get().

- Add GetHeaderFromCachedMap helper for extracting headers from cached map
- Add ExtractWantedHeadersFromCachedMap to extract context headers from cached map
- Update jsonRPC, rest, and tendermintRPC handlers to cache headers early
- Fix redundant fiberCtx.Get() call in rest.go handlerUse

This reduces per-request allocations by consolidating multiple header
access calls into a single GetReqHeaders() call with map lookups.
@github-actions

github-actions Bot commented Jan 12, 2026

Copy link
Copy Markdown

Test Results

    7 files  ±0    128 suites  ±0   33m 25s ⏱️ -51s
3 187 tests ±0  3 186 ✅ ±0  1 💤 ±0  0 ❌ ±0 
3 270 runs  ±0  3 269 ✅ ±0  1 💤 ±0  0 ❌ ±0 

Results for commit 2b2166b. ± Comparison against base commit 3a00012.

♻️ This comment has been updated with latest results.

@pull-request-size pull-request-size Bot added size/L and removed size/M labels Jan 13, 2026
@nimrod-teich nimrod-teich changed the title perf: cache fiber request headers to reduce allocations perf: reduce memory allocations in logging and HTTP response handling Jan 13, 2026
@nimrod-teich nimrod-teich force-pushed the perf/cache-fiber-headers branch 2 times, most recently from 9ad1b6c to 2b2166b Compare January 19, 2026 10:29
@pull-request-size pull-request-size Bot added size/M and removed size/L labels Jan 19, 2026
@nimrod-teich nimrod-teich changed the title perf: reduce memory allocations in logging and HTTP response handling perf: cache fiber request headers to reduce allocations Jan 19, 2026

@NadavLevi NadavLevi 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.

Please rebase on top of main

@nimrod-teich nimrod-teich merged commit b6477b2 into main Jan 19, 2026
16 checks passed
@nimrod-teich nimrod-teich deleted the perf/cache-fiber-headers branch January 19, 2026 11:12
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.

2 participants