Skip to content

Conversation

@pjfanning
Copy link
Member

@pjfanning pjfanning commented Oct 5, 2025

  • Needs a change in 2.0.0 ByteString (new indexOf(char, start, end))
  • does the illegal char check slightly later but rolls it in with the code to create the headerName String so it shouldn't reduce happy path perf - but the illegal char will be reported slightly later in the worst case
  • the ByteString indexOf should perform better than the existing code in the happy path

@pjfanning pjfanning force-pushed the rework-header-name-scan branch from caf78cb to 89470c1 Compare October 5, 2025 16:20
Update HttpHeaderParser.scala

Update HttpHeaderParser.scala
@pjfanning pjfanning force-pushed the rework-header-name-scan branch from 89470c1 to 59b78eb Compare December 18, 2025 15:10
@pjfanning pjfanning marked this pull request as draft December 18, 2025 15:10
@pjfanning pjfanning changed the title [EXPERIMENT] Rework header name scan Rework header name scan to use optimised ByteString.indexOf Dec 19, 2025
@pjfanning pjfanning marked this pull request as ready for review December 19, 2025 00:30
@pjfanning pjfanning added this to the 2.0.0-M1 milestone Dec 19, 2025
@mdedetrich
Copy link
Contributor

Are there benchmarks for this, if so can you post the difference otherwise would it be possible to create some benchmarks and post the results?

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the HTTP header name scanning logic to use an optimized ByteString.indexOf method instead of character-by-character scanning. The primary goal is to improve performance in the happy path by leveraging native indexOf implementation.

  • Replaces scanHeaderNameAndReturnIndexOfColon with direct indexOf call and two new helper functions
  • Moves illegal character validation to occur during header name string construction rather than during colon search
  • Validates the entire header name (from lineStart to colon) rather than only the portion after trie matching

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pjfanning pjfanning marked this pull request as draft December 19, 2025 08:01
@pjfanning
Copy link
Member Author

Are there benchmarks for this, if so can you post the difference otherwise would it be possible to create some benchmarks and post the results?

I'll come up with some benchmark numbers

@pjfanning
Copy link
Member Author

I ran the existing benchmark and the results are similar, with and without this change.

HeaderParserBenchmark.bench_parse_headers

I'll leave this for now but may come back to it to see if it is worth continuing.

@pjfanning pjfanning removed this from the 2.0.0-M1 milestone Dec 19, 2025
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