perf: use pointer indirection for BMW term state ordering#249
Merged
perf: use pointer indirection for BMW term state ordering#249
Conversation
Change the TpTermState array from contiguous structs to an array of pointers. This makes restore_ordering swap 8-byte pointers via memmove instead of ~200-byte TpTermState structs, reducing CPU overhead for the sorted-order maintenance in the WAND traversal hot loop. Profiling on 138M MS-MARCO v2 passages showed restore_ordering at 21.7% of CPU time for multi-token queries (5-8 tokens). The large struct size (~200 bytes due to embedded TpSegmentPostingIterator) made each memmove expensive.
tjgreen42
added a commit
that referenced
this pull request
Mar 3, 2026
## Summary - Update comparison page with results from benchmark run [22642807624](https://github.com/timescale/pg_textsearch/actions/runs/22642807624) - Overall throughput improved from 2.8x to 3.2x faster than System X - Build time gap narrowed from 2.0x to 1.6x (270s → 234s) - Key improvements since Feb 9: SIMD bitpack decoding (#250), stack-allocated decode buffers (#253), BMW term state pointer indirection (#249), arena allocator rewrite (#231), leader-only merge (#244) ## Testing - Numbers extracted from benchmark run on commit 1b09cc9 - gh-pages branch also needs updating (will push after merge)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TpTermState *terms(contiguous struct array) toTpTermState **terms(array of pointers) in the BMW scoring enginerestore_orderingnow moves 8-byte pointers via memmove instead of ~200-byteTpTermStatestructs (~25x reduction in bytes moved)&terms[i]→terms[i]and.field→->fieldchangesMotivation
Profiling multi-token queries (5-8 tokens) on 138M MS-MARCO v2 passages showed
restore_orderingconsuming 21.7% of CPU time. TheTpTermStatestruct is ~200 bytes due to the embeddedTpSegmentPostingIterator(which containsTpDictEntry,TpSkipEntry,TpSegmentDirectAccess, etc.). Every time a term advances in the WAND traversal, the sorted order is restored by memmove-ing these large structs.Test plan
make installcheck)