Skip to content

perf: software prefetch bitmask filter K=8 steps ahead in iterate_to_… - #1270

Merged
cave-g-f merged 1 commit into
jegao/LabelHotFixfrom
deyu/perf
Jul 27, 2026
Merged

perf: software prefetch bitmask filter K=8 steps ahead in iterate_to_…#1270
cave-g-f merged 1 commit into
jegao/LabelHotFixfrom
deyu/perf

Conversation

@cave-g-f

Copy link
Copy Markdown

…fixed_point

Reduces contain_filtered_label self-cost from 49.2% to 14.3% by hiding DRAM latency on the random-access node bitmask load. Measured on DANNMemoryTable with 21M-node index, 189 filter labels, 12 threads: QPS 7,705 -> 12,435 (+61.4%), P99 3012us -> 1656us (-45%).

Changes:

  • filter_match_proxy: add prefetch_bitmask(id) virtual method that issues _mm_prefetch on the node's bitmask address. No-op for the integer_label path.
  • iterate_to_fixed_point: pre-prefetch first K=8 neighbors' bitmasks before the loop, then sliding-window prefetch K steps ahead inside the loop. Guarded by use_filter to avoid overhead on unfiltered queries. Applied to both dynamic and static graph paths.
  • Use NeighborList::data() for indexed access (no operator[]).
  • Also brings AVX2 buffer padding from downstream d9583a32:
    • bitmask_filter_match ctor: query_bitmask_buf resized to at least 4 words for safe 256-bit loads.
    • build_bitmask_index: node bitmask buffer padded with 4 extra uint64 words at end for safe AVX2 reads on the last node.

The prefetch instruction itself accounts for 11% self-cost in the post- optimization profile, which is the expected steady-state cost of hiding the DRAM stall on 44 billion filter checks (4.6M queries x 200 search list x ~48 out-edges).

  • Does this PR have a descriptive title that could go in our release notes?
  • Does this PR add any new dependencies?
  • Does this PR modify any existing APIs?
  • Is the change to the API backwards compatible?
  • Should this result in any changes to our documentation, either updating existing docs or adding new ones?

Reference Issues/PRs

What does this implement/fix? Briefly explain your changes.

Any other comments?

@hildebrandmw hildebrandmw added the C++ Pull Request targeting C++ label Jul 23, 2026
Comment thread src/index.cpp
assert(id < _max_points);

// Prefetch bitmask K steps ahead (sliding window)
if (use_filter && i + BITMASK_PREFETCH_K < nbrs_count)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can move the prefetch part after visited check?

@cave-g-f
cave-g-f force-pushed the deyu/perf branch 2 times, most recently from 8316e9a to bebff14 Compare July 27, 2026 08:10
…fixed_point

Reduces contain_filtered_label self-cost from 49.2% to 14.3% by hiding
DRAM latency on the random-access node bitmask load. Measured on
DANNMemoryTable with 21M-node index, 189 filter labels, 12 threads:
QPS 7,705 -> 12,435 (+61.4%), P99 3012us -> 1656us (-45%).

Changes:
- filter_match_proxy: add prefetch_bitmask(id) virtual method that
  issues _mm_prefetch on the node's bitmask address. No-op for the
  integer_label path.
- iterate_to_fixed_point: pre-prefetch first K=8 neighbors' bitmasks
  before the loop, then sliding-window prefetch K steps ahead inside
  the loop. Guarded by use_filter to avoid overhead on unfiltered
  queries. Applied to both dynamic and static graph paths.
- Use NeighborList::data() for indexed access (no operator[]).
- Also brings AVX2 buffer padding from downstream d9583a32:
  * bitmask_filter_match ctor: query_bitmask_buf resized to at least
    4 words for safe 256-bit loads.
  * build_bitmask_index: node bitmask buffer padded with 4 extra
    uint64 words at end for safe AVX2 reads on the last node.

The prefetch instruction itself accounts for 11% self-cost in the post-
optimization profile, which is the expected steady-state cost of hiding
the DRAM stall on 44 billion filter checks (4.6M queries x 200 search
list x ~48 out-edges).
@cave-g-f
cave-g-f merged commit 5fb50a7 into jegao/LabelHotFix Jul 27, 2026
3 of 39 checks passed
@cave-g-f
cave-g-f deleted the deyu/perf branch July 27, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C++ Pull Request targeting C++

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants