HeaderUtils: more efficient handling of optional/exotic charsets
- Dominant language
- Java
- Stars
- 1k
- Forks
- 229
- Avg merge
- 23h 23m
- Merged PRs (30d)
- 16
Description
While fixing Default Serializer in #891 we've identified [1] an area of performance improvement in `HeaderUtils`.
In case `hasContentType()` doesn't match the exact content-type with charset, we fall back to a `String` compare or a more complex regex match. This means we're doing an `AsciiBuffer` (the optimized underlying ServiceTalk construct for headers) to `String` conversion and performing multiple passes over the `Buffer` to compare.
We should be able to create a method in the `CharSequences` utility that performs a prefix with optional suffix match in a single pass, leveraging `ByteProcessor` on `AsciiBuffer` and avoid both both: `String` conversion and regex matching.
[1] https://github.com/apple/servicetalk/pull/891#issuecomment-564207308
Contributor guide
Research direction
Start by tracing HeaderUtils.hasContentType() and the CharSequences utility, then inspect how AsciiBuffer and ByteProcessor are used for header comparisons. Done means optional or exotic charsets are matched in a single pass without converting to String or using regex matching, with the relevant tests updated or added.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- networking
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 43/100