Repository navigation
perf(parser): SIMD crlf-pair match and scalar hot-path fixes - #374
Merged
Merged
Conversation
Replace the find-CR-then-check loop in cwist_simd_find_crlfcrlf with a
paired matcher inside the existing compile-time arch ladder (AVX2/SSE2/
NEON/RVV/AltiVec/MSA): four unaligned loads at j..j+3 are compared
against \r\n\r\n and ANDed, so every offset is tested in one pass and
bare-'\r'-heavy data no longer causes an O(n*k) rescan. The memchr/SWAR
scalar tail is kept for the vector-safety margin and non-vector builds.
query.c hot paths: url_decode drops the per-escape sscanf("%2x") call
in favor of an isxdigit guard plus a 256-entry nibble table, copying
plain runs in bulk via strcspn; malformed escapes still pass through
literally, byte for byte. cwist_query_map_parse replaces strtok_r +
strchr with a single pass over the query_strdup copy using memchr,
preserving strtok's empty-token collapsing and the arena/lifetime
contract.
Tests: new tests/test_simd_parser.c covers the paired matcher including
bare-'\r'-heavy input and vector-boundary-straddling matches;
test_core_utils gains malformed-escape and delimiter-edge cases for the
query map.
gg582
added a commit
that referenced
this pull request
Oct 13, 2026
perf(parser): SIMD crlf-pair match and scalar hot-path fixes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a paired SIMD matcher for "\r\n\r\n" inside the existing compile-time arch ladder in simd_parser.h, eliminating the O(n·k) rescan on bare-'\r' data, and rewrites the query.c hot paths: url_decode uses a hex table instead of per-escape sscanf, and cwist_query_map_parse is a single memchr-driven pass without strtok_r.
End-to-end wrk on cwist_bench is flat (this workload barely touches the query path), but the url_decode micro-bench (2000 escapes, 1M decodes) shows 12.8x:
All existing tests pass, plus new tests/test_simd_parser.c (paired matcher, bare-'\r'-heavy and vector-boundary cases) and malformed-escape query-map cases in test_core_utils.