Skip to content

Conversation

@MauriceVanVeen
Copy link
Member

When ingesting messages into a JetStream stream, the speed becomes limited if headers are set on a message due to needing to do all header checks. These header checks currently continuously re-scan the headers for different keys, instead of indexing these headers once and then being able to fetch the values quickly.

This PR proposes an improvement by indexing the headers once and using that throughout for stream ingest. Using an async publish benchmark with the only header of k: v (just to contain headers and require the server to scan even if the server doesn't need to act on them), for both R1 and R3 there's a performance improvement between 12-26%. Using a R1 with PersistMode: async (async flush) even shows a performance improvement of ~39% (915k msgs/s -> 1.3M msgs/s).

The current implementation of a pointer to jsHdrIndex, the usage of sync.Pool and referencing []byte was benchmarked and came out as the most performant when compared with a map to a range or []byte, without returning a pointer, and when returning a range into hdr instead of []byte.

Signed-off-by: Maurice van Veen [email protected]

@MauriceVanVeen MauriceVanVeen marked this pull request as ready for review October 23, 2025 12:45
@MauriceVanVeen MauriceVanVeen requested a review from a team as a code owner October 23, 2025 12:45
Copy link
Contributor

@sciascid sciascid left a comment

Choose a reason for hiding this comment

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

I'd love to see the getters, as mentioned in the first comment, unless you see downsides. The second comment is totally optional, and just for consideration.

Copy link
Contributor

@sciascid sciascid left a comment

Choose a reason for hiding this comment

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

LGTM

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.

3 participants