Skip to content

Optimize B-tree node shifts for trivially copyable values#25

Open
sukeya wants to merge 1 commit intomainfrom
codex/add-type-trait-branching-in-shift_values
Open

Optimize B-tree node shifts for trivially copyable values#25
sukeya wants to merge 1 commit intomainfrom
codex/add-type-trait-branching-in-shift_values

Conversation

@sukeya
Copy link
Owner

@sukeya sukeya commented Feb 11, 2026

Motivation

  • Improve performance of value shifting inside B-tree nodes by taking a fast path for trivially copyable value types.
  • Ensure overlapping memory moves in left/right shifts are performed safely and efficiently for contiguous trivial types.

Description

  • Added includes <cstring>, <memory>, and <type_traits> and branched shift_values_right / shift_values_left on std::is_trivially_copyable_v<mutable_value_type>.
  • Fast path uses std::to_address(begin) + std::memmove to move contiguous regions for trivially copyable mutable_value_type while keeping the existing std::move_backward / std::move paths for non-trivial types.
  • Documented in comments that std::memmove handles overlapping ranges so right/left shifts remain well-defined for the fast path.
  • Registered focused benchmarks in benchmark/btree_bench.cpp to exercise trivial-ish types (int and std::pair<int,int>) for Insert/Delete on Set and Map to observe performance differences.

Testing

  • Configured the project with cmake -S . -B build which completed successfully.
  • Built the main targets with cmake --build build -j4 which completed successfully.
  • Attempted to build the benchmark subproject with cmake -S . -B build-bench -DPLATANUS_BUILD_BENCHMARK=ON but it failed due to inability to fetch https://github.com/google/benchmark.git in this environment (network restriction), so benchmarks could not be executed here.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant