next.js
384cb2da - Turbopack Persistence: Improve heuristic for compacted database access (#89497)

Commit
2 days ago
Turbopack Persistence: Improve heuristic for compacted database access (#89497) ### What? Adjusts block sizing constants and heuristics in turbo-persistence to improve the balance between small and medium values, reduce block count, and improve access performance. ### Changes 1. **`MAX_SMALL_VALUE_SIZE`**: 64 KiB → **4 KiB**. Values up to 4 KiB are now stored as small values (packed into shared blocks). Values larger than 4 KiB become medium values with dedicated blocks that can be copied without decompression during compaction. 2. **`MAX_SMALL_VALUE_BLOCK_SIZE` → `MIN_SMALL_VALUE_BLOCK_SIZE`**: Renamed and changed from a maximum (64 KiB) to a **minimum (8 KiB)**. Small value blocks are now emitted once they accumulate at least 8 KiB, resulting in actual block sizes of 8–12 KiB. 3. **`KEY_BLOCK_ENTRY_META_OVERHEAD`**: Updated from 8 to 20 to reflect the actual worst-case overhead per entry in a key block (type, position, hash, block index, size, position in block). 4. **Block count overflow protection**: Added `ValueBlockCountTracker` to prevent exceeding the u16 block index limit (`MAX_VALUE_BLOCK_COUNT = u16::MAX / 2`), which accounts for the 50/50 merge-and-split during compaction. 5. **README**: Updated value type documentation with size boundaries and added a trade-off table covering compression, compaction, access cost, and storage overhead. ### Value type trade-offs | | Inline | Small | Medium | Blob | | --------------------- | --------- | --------------------------- | --------------------- | ----------------------------------------- | | Size | ≤ 8 B | 9 B .. 4 kB | 4 kB .. 64 MB | > 64 MB | | Compression unit size | ≤ 16 kB | 8 kB .. 12 kB | 4 kB .. 64 MB | > 64 MB | | Access cost | none | decompress ~8 kB | decompress value size | open file, decompress value size | | Compaction | re-compressed | re-compressed | copied compressed | pointer copied |
Author
Parents
Loading