perf: inline branchless decompression helpers (fixes #251) - #259
Open
jdymitarai wants to merge 1 commit into
Open
perf: inline branchless decompression helpers (fixes #251)#259jdymitarai wants to merge 1 commit into
jdymitarai wants to merge 1 commit into
Conversation
In GCC shared-library builds (BUILD_SHARED_LIBS=ON, e.g. on AArch64 and other platforms), MemCopy64, ClearDeferred, and DeferMemCopy were not inlined by GCC because they were not explicitly declared inline, leading to indirect PLT calls in the tight inner decompression loop. Annotating these helpers with SNAPPY_ATTRIBUTE_ALWAYS_INLINE inline allows GCC to inline them as intended, improving throughput by 12% to 49% across decompression benchmarks. Fixes google#251
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 of changes
When building Snappy as a shared library (
BUILD_SHARED_LIBS=ON) under GCC (e.g. GCC 10/12 on AArch64 and other platforms), small helpers in the branchless decompression path (MemCopy64,ClearDeferred,DeferMemCopy) were not automatically inlined by GCC, resulting in PLT overhead within the tight decompression loop.Following the guidance in #251, this patch adds
SNAPPY_ATTRIBUTE_ALWAYS_INLINE inlineannotations to:MemCopy64(char* dst, const void* src, size_t size)MemCopy64(ptrdiff_t dst, const void* src, size_t size)ClearDeferred(const void** deferred_src, size_t* deferred_length, uint8_t* safe_source)DeferMemCopy(const void** deferred_src, size_t* deferred_length, const void* src, size_t length)Matching the existing pattern used by
AdvanceToNextTagARMOptimizedand related functions.Benchmark Impact
As benchmarked in #251, inlining these helpers yields significant throughput gains under GCC shared builds:
BM_UFlatMedley: +12.5% to +14.0%BM_UValidateMedley: +44.6% to +49.2%Fixes #251