Repository navigation
escape: use hex-pair lookup in curl_easy_escape - #23021
Merged
Merged
Conversation
cmeister2
added a commit
that referenced
this pull request
Sep 21, 2026
Copy precomputed uppercase hex pairs instead of looking up each digit separately. Preserve literal-run batching and allocation behavior. Add coverage for all 256 byte values, checking exact encoded output and round-trip decoding. Closes #23021
cmeister2
force-pushed
the
cm2/urlencode
branch
from
September 21, 2026 14:10
acec0de to
acec0de
Compare
cmeister2
added a commit
that referenced
this pull request
Sep 21, 2026
Copy precomputed uppercase hex pairs instead of looking up each digit separately. Preserve literal-run batching and allocation behavior. Add coverage for all 256 byte values, checking exact encoded output and round-trip decoding. Closes #23021
cmeister2
force-pushed
the
cm2/urlencode
branch
from
September 21, 2026 14:22
acec0de to
acec0de
Compare
Copy precomputed uppercase hex pairs instead of looking up each digit separately. Preserve literal-run batching and allocation behavior. Add coverage for all 256 byte values, checking exact encoded output and round-trip decoding. Closes #23021
cmeister2
force-pushed
the
cm2/urlencode
branch
from
September 21, 2026 14:26
acec0de to
acec0de
Compare
bagder
approved these changes
Sep 21, 2026
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.
Summary
Use a precomputed uppercase hex-pair table in
curl_easy_escape(),replacing two separate digit lookups with a two-byte
memcpy.Preserve literal-run batching, allocation bounds, character classification,
and NUL termination. The table adds 513 bytes before alignment. Using
memcpyavoids alignment, aliasing, and endianness assumptions.Add regression coverage for all 256 byte values, checking exact encoded
output and decoded bytes, length, and termination.
Performance
Saved measurements of this encoder change against baseline
acec0de3921d2e5eb435410dbe4b2171b5097e9a:-O2 -DNDEBUG, static libcurl, Intel Core Ultra 7 165H, WSL2.to CPU 2. Allocation and freeing remain inside the timed loop.
urlencode: 248.942 → 186.344 ns/call, 25.15% less time.The candidate was faster in all five pairs.
These are earlier measurements, not a fresh benchmark of this branch.
Caveat: The unchanged
urldecodebenchmark was 8.69% slower(228.330 → 248.172 ns/call) in the same comparison. Code and table placement
changed, but the cause remains unproven. Further measurements on a native
host or with other compiler/link layouts are needed before claiming a net
performance improvement.
Generated Assembly
GCC's x86-64 escaped-byte block, including loop-end control. Classification,
literal-run flushing, allocation, and termination are outside these excerpts.
At entry,
r12holds the input byte andrcxpoints to its output slot.Before
After
The block shrinks from 14 to 8 instructions, with one table load instead
of two and two output stores instead of three. The two-byte
memcpyisinlined; output size is unchanged. These are instruction counts, not cycles.
Validation