Skip to main content

Module key_buffer

Module key_buffer 

Source
Expand description

Cache-Line Aligned Key Buffer with Stack Allocation

This module provides zero-allocation key construction for database operations. Every database operation currently allocates a heap string via format!(), which is inefficient for high-throughput scenarios.

§Problem Analysis

let path = format!("{}/{}/{}", table, row_id, col.name);  // HEAP ALLOC!

Allocation costs:

  • format!() calls alloc::alloc::alloc() → ~50-100 cycles
  • Cache pollution from temporary allocations
  • GC pressure in concurrent scenarios

§Solution

Stack-allocated, cache-line aligned key buffers:

  • Zero heap allocation
  • Cache-line aligned for optimal memory access
  • Pre-computed table prefixes for repeated operations

§Performance

Current: T_key ≈ 83ns (allocation + formatting) Proposed: T_key ≈ 15ns (stack buffer + fast formatting) Speedup: 5.5×

Structs§

ArenaKey
Zero-copy key reference into arena memory
ArenaKeyHandle
An owned key handle that can be stored in DashMap, SkipMap, etc.
BatchKeyGenerator
Batch key generator for bulk operations
InternedTablePrefix
Interned table prefix for repeated use
KeyArena
Thread-local arena allocator for key buffers
KeyBuffer
Fixed-size key buffer - NO HEAP ALLOCATION

Constants§

MAX_KEY_LENGTH
Maximum key length (cache line - length byte)