Skip to content

feat: add monotomic/slab allocator - #779

Open
kexianda wants to merge 2 commits into
bytedance:mainfrom
kexianda:allocator2
Open

feat: add monotomic/slab allocator#779
kexianda wants to merge 2 commits into
bytedance:mainfrom
kexianda:allocator2

Conversation

@kexianda

@kexianda kexianda commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

  1. HashStringAllocator and memory::StlAllocator are very slow:
    add monotomic/slab allocator to accelerate them.

  2. StringView:
    In some cases(Agg) HashStringAllocator is used. Adding a contigous flag in the high bit of pointer
    for compatibility. And improve the performance.

  3. add allocation strategy for AlignedBuffer to reduce memory fragment waste

Issue Number: close #789

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 🚀 Performance improvement (optimization)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)
  • 🔨 Refactoring (no logic changes)
  • 🔧 Build/CI or Infrastructure changes
  • 📝 Documentation only

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
    Paste your google-benchmark or TPC-H results here.
    Before: 10.5s
    After:   8.2s  (+20%)
    
  • Negative Impact: Explained below (e.g., trade-off for correctness).

Release Note

Please describe the changes in this PR

Release Note:

Release Note:
- Fixed a crash in `substr` when input is null.
- optimized `group by` performance by 20%.

Checklist (For Author)

  • I have added/updated unit tests (ctest).
  • I have verified the code with local build (Release/Debug).
  • I have run clang-format / linters.
  • (Optional) I have run Sanitizers (ASAN/TSAN) locally for complex C++ changes.
  • No need to test or manual test.

Breaking Changes

  • No

  • Yes (Description: ...)

    Click to view Breaking Changes
    Breaking Changes:
    - Description of the breaking change.
    - Possible solutions or workarounds.
    - Any other relevant information.
    

kexianda added 2 commits July 24, 2026 16:48
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.
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.

[Feature] Adopt new allocators for fast allocating and reduce RSS

1 participant