Skip to content

compress: Elide long-offset path on 64-bit - #4772

Open
uarif1 wants to merge 1 commit into
facebook:devfrom
uarif1:elide32bit
Open

compress: Elide long-offset path on 64-bit#4772
uarif1 wants to merge 1 commit into
facebook:devfrom
uarif1:elide32bit

Conversation

@uarif1

@uarif1 uarif1 commented Sep 8, 2026

Copy link
Copy Markdown

ZSTD_seqToCodes() only enables longOffsets on 32-bit builds because the 64-bit bitstream accumulator can hold every supported offset. However, ZSTD_encodeSequences_body() still tests the runtime flag for the first sequence and every sequence in its hot loop.

Make the architecture condition explicit at both branches so 64-bit compilers can discard the unreachable path. Add an assertion documenting the invariant while preserving the existing 32-bit behavior.

In five alternating GCC 11.5 fullbench runs encoding sequences for an 8 MiB, 50%-compressible level-3 sample, throughput increased from 1201.6 to 1213.4 MB/s on average (+1.0%) with identical 2,706,887-byte output. The fullbench text section also shrank by 512 bytes.

ZSTD_seqToCodes() only enables longOffsets on 32-bit builds because the
64-bit bitstream accumulator can hold every supported offset. However,
ZSTD_encodeSequences_body() still tests the runtime flag for the first
sequence and every sequence in its hot loop.

Make the architecture condition explicit at both branches so 64-bit
compilers can discard the unreachable path. Add an assertion documenting
the invariant while preserving the existing 32-bit behavior.

In five alternating GCC 11.5 fullbench runs encoding sequences for an
8 MiB, 50%-compressible level-3 sample, throughput increased from
1201.6 to 1213.4 MB/s on average (+1.0%) with identical 2,706,887-byte
output. The fullbench text section also shrank by 512 bytes.

Signed-off-by: Usama Arif <usama.arif@linux.dev>
@meta-cla meta-cla Bot added the CLA Signed label Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant