servicetalk icon indicating copy to clipboard operation
servicetalk copied to clipboard

HeaderUtils: more efficient handling of optional/exotic charsets

Open jayv opened this issue 5 years ago • 0 comments

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

jayv avatar Dec 12 '19 17:12 jayv