Skip to content

B+Tree performance optimization: 128-byte nodes + algorithmic improvements - #105

Merged
nockawa merged 7 commits into
mainfrom
feature/98-btree-optimization
Feb 26, 2026
Merged

nockawa merged 7 commits into
mainfrom
feature/98-btree-optimization

Conversation

@nockawa

@nockawa nockawa commented Feb 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #98

Comprehensive B+Tree performance optimization across 4 phases, delivering major throughput improvements:

  • Phase 1: Smarter chunk initialization (eliminate ZeroMemoryInternal), cache IsLeaf in NodeWrapper, append fast-path via cached last key
  • Phase 2: Lazy NodeRelatives — defer sibling loading until spill/split/borrow/merge (~5% of ops)
  • Phase 3: 128-byte node chunks (doubled from 64), leveraging Adjacent Cache Line Prefetch. Tree height drops from ~10 to ~6-7 levels for 1M keys — the dominant optimization
  • Phase 4: Iterative tree descent replacing recursive InsertInternal/RemoveInternal with stackalloc path arrays
  • Additional: Sealed leaf storage classes (JIT GDV), IComparer specialization (eliminate interface dispatch), cached ChunkAccessor in BTree, new Insert_Random benchmark

Results (vs main baseline)

Operation main Optimized Improvement
Lookup (hit) 285.3 ns ~200 ns -30%
Lookup (miss) 212.8 ns ~172 ns -19%
Insert (sequential) 771.3 ns ~360 ns -53%
Delete 858.7 ns ~651 ns -24%
Seq. scan (100) 184.9 ns ~129 ns -30%

Test plan

  • All existing B+Tree tests pass after each phase
  • BTree.Add benchmark shows ≥40% improvement over baseline
  • BTree.TryGet benchmark shows ≥30% improvement over baseline
  • No regression in Remove or RangeScan performance

🤖 Generated with Claude Code

@nockawa
nockawa merged commit 46dd2f1 into main Feb 26, 2026
5 checks passed
@nockawa
nockawa deleted the feature/98-btree-optimization branch February 26, 2026 08:31
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.

B+Tree Performance Optimization (128-byte nodes + algorithmic improvements)

1 participant