feat: add monotomic/slab allocator - #779
Open
kexianda wants to merge 2 commits into
Open
Conversation
HashStringAllocator and memory::StlAllocator are slow for small, frequent allocations. Add monotonic and slab allocators to accelerate these allocation patterns. Microbenchmarks show that SlabAllocator is about 4x faster than HashStringAllocator and about 40x faster than memory::StlAllocator. ``` ============================================================================ [...]s/unstable/SlabAllocatorBenchmark.cpp relative time/iter iters/s ============================================================================ HashStringAllocatorFifoAllocFree256K_8Threads 58.47ns 17.10M AlignedStlAllocatorFifoAllocFree256K_8Threads 10.372% 563.70ns 1.77M SlabAllocatorFifoAllocFree256K_8Threads 384.63% 15.20ns 65.79M ``` In the append-only scenario, the monotonic allocator is about 12x faster than HashStringAllocator. ``` ============================================================================ [...]StringMonotonicAllocatorBenchmark.cpp relative time/iter iters/s ============================================================================ HashStringAllocatorAllocateNoFree 6.22s 160.90m MonotonicMemoryResourceAllocateNoFree 1287.9% 482.60ms 2.07 ``` For StringView compatibility, keep supporting cases where HashStringAllocator is still used, such as aggregation. Store a contiguous-string flag in the high bit of the pointer to preserve compatibility while enabling faster paths.
…mentation AlignedBuffer backs vectors and is also used throughout the codebase. Its existing growth policy increases capacity aggressively, typically by 1.5x or by rounding up to a power of two. While this is appropriate for growable buffers, it can waste substantial memory when the final size is known in advance. The issue is more pronounced with jemalloc: oversized requests may be rounded up again to jemalloc size classes, compounding internal fragmentation. Introduce allocation strategies tailored to different use cases. Fixed-size buffers now use a conservative strategy that allocates only the required SIMD-aligned capacity, while growable buffers retain the existing aggressive growth strategy to reduce reallocations. This reduces internal fragmentation and lowers process RSS without compromising the performance of buffers that need to grow.
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.
What problem does this PR solve?
HashStringAllocator and memory::StlAllocator are very slow:
add monotomic/slab allocator to accelerate them.
StringView:
In some cases(Agg) HashStringAllocator is used. Adding a contigous flag in the high bit of pointer
for compatibility. And improve the performance.
add allocation strategy for AlignedBuffer to reduce memory fragment waste
Issue Number: close #789
Type of Change
Description
Describe your changes in detail.
For complex logic, explain the "Why" and "How".
Performance Impact
No Impact: This change does not affect the critical path (e.g., build system, doc, error handling).
Positive Impact: I have run benchmarks.
Click to view Benchmark Results
Negative Impact: Explained below (e.g., trade-off for correctness).
Release Note
Please describe the changes in this PR
Release Note:
Checklist (For Author)
Breaking Changes
No
Yes (Description: ...)
Click to view Breaking Changes