Skip to content

perf: optimize query hot paths#16

Merged
MnO2 merged 1 commit into
MnO2:masterfrom
messense:perf/query-optimizations
Apr 13, 2026
Merged

perf: optimize query hot paths#16
MnO2 merged 1 commit into
MnO2:masterfrom
messense:perf/query-optimizations

Conversation

@messense
Copy link
Copy Markdown
Contributor

@messense messense commented Apr 13, 2026

  • Inline single-byte traversal in PrefixIter::next() instead of calling find() with 1-byte slices per byte
  • Add unchecked indexing helpers (node_unchecked, ninfo_unchecked) with debug_assert guards for find/begin/next inner loops
  • Derive Copy on Node and NInfo (small POD types)
  • Eliminate .clone() on hot paths in pop_e_node, erase__, pop_block
  • Add #[inline] to find, begin, next methods
  • Fix benchmarks to isolate build from query time

Benchmark results vs baseline on Apple M4 Max:

  • exact_match_search: 10.99ns -> 9.07ns (~17%)
  • common_prefix_search: 25.60ns -> 23.01ns (~10%)
  • common_prefix_predict: 87.35ns -> 68.71ns (~21%)

- Inline single-byte traversal in PrefixIter::next() instead of
  calling find() with 1-byte slices per byte
- Add unchecked indexing helpers (node_unchecked, ninfo_unchecked)
  with debug_assert guards for find/begin/next inner loops
- Derive Copy on Node and NInfo (small POD types)
- Eliminate .clone() on hot paths in pop_e_node, erase__, pop_block
- Add #[inline] to find, begin, next methods
- Fix benchmarks to isolate build from query time

Benchmark results vs baseline:
  exact_match_search:     10.99ns -> 9.07ns  (~17%)
  common_prefix_search:   25.60ns -> 23.01ns (~10%)
  common_prefix_predict:  87.35ns -> 68.71ns (~21%)
@messense messense force-pushed the perf/query-optimizations branch from afc9e15 to da7ba11 Compare April 13, 2026 12:21
@MnO2 MnO2 merged commit 655b440 into MnO2:master Apr 13, 2026
6 checks passed
@MnO2
Copy link
Copy Markdown
Owner

MnO2 commented Apr 13, 2026

Thanks for the PR. I'll release the latest change as soon as I have time.

@messense messense deleted the perf/query-optimizations branch April 13, 2026 23:57
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.

2 participants