Skip to content

perf: inline branchless decompression helpers (fixes #251) - #259

Open
jdymitarai wants to merge 1 commit into
google:mainfrom
jdymitarai:fix-inline-helpers-251
Open

perf: inline branchless decompression helpers (fixes #251)#259
jdymitarai wants to merge 1 commit into
google:mainfrom
jdymitarai:fix-inline-helpers-251

Conversation

@jdymitarai

Copy link
Copy Markdown

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 inline annotations 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 AdvanceToNextTagARMOptimized and 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%
  • Real-world datasets (Silesia, itemdata): +12.4% to +16.0%

Fixes #251

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Question about inlining three small helpers in GCC 10/12 AArch64 shared builds

1 participant