Refactor/prefetch select cleanup#409
Conversation
- _prefetch_hbm_direct_path: hoist admitted_keys/tids/scores/positions computation above erase and reuse them, removing the duplicate missing_keys[admit_mask]/missing_table_ids[admit_mask] gathers. - _prefetch_cache_path: simplify non_admit_miss to ~keys_to_insert_mask; the & new_in_miss term is a no-op since keys_to_insert_mask keeps storage-found positions True, so ~keys_to_insert_mask is already a subset of new_in_miss. No behavior change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
/build |
Greptile SummaryThis PR refactors two prefetch functions (
Confidence Score: 5/5Safe to merge — both changed paths produce identical results to the original code. The refactoring replaces integer-index extraction (torch.where + fancy indexing) with direct boolean-mask indexing throughout both prefetch paths. In _prefetch_cache_path, keys_to_insert_mask[new_in_miss] = admit_mask is equivalent to the old keys_to_insert_mask[new_miss_indices[admit_mask]] = True because the non-admitted positions were already False from the storage_founds.clone() initialization, and the wider ~keys_to_insert_mask for non-admitted-position computation remains limited to non-storage-found, non-admitted slots. In prefetch_hbm_direct_path, pre-computing admitted* before the erase and passing them directly instead of re-slicing is a pure reorganization. No edge-case regressions were found. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["miss_keys / miss_tids"] --> B{"new_in_miss.any AND admit_strategy?"}
B -- "No admit_strategy" --> C["keys_to_insert_mask = all-ones"]
B -- "Yes" --> D["Slice: new_keys_sub = miss_keys[new_in_miss]"]
D --> E["admission_counter.add → freq"]
E --> F["admit_strategy.admit → admit_mask"]
F --> G{"admit_mask.any?"}
G -- "Yes" --> H["admission_counter.erase admitted keys"]
H --> I["keys_to_insert_mask[new_in_miss] = admit_mask"]
G -- "No" --> J["new_in_miss positions remain False"]
I --> K["non_admit_miss = ~keys_to_insert_mask"]
J --> K
K --> L{"non_admit_miss.any?"}
L -- "Yes" --> M["non_admitted_positions = miss_compact_idx[non_admit_miss]"]
L -- "No" --> N["non_admitted_positions = None"]
M --> O{"keys_to_insert_mask.any?"}
N --> O
O -- "No" --> P["Set slot_indices = -1, return early"]
O -- "Yes" --> Q["flagged_compact → insert_keys / insert_tids"]
Q --> R["cache.insert_and_evict"]
C --> O
Reviews (2): Last reviewed commit: "Merge branch 'main' into refactor/prefet..." | Re-trigger Greptile |
|
❌ Pipeline #53032067 -- failed
Result: 12/14 jobs passed |
|
TODO: benchmark it |
|
The performance is aligned with before, and all tests have passed. It can be merged |

Description
Checklist