Skip to content

Count snapshot alias costs with prefix sums (fixes #319) - #346

Merged
yatesdr merged 1 commit into
NVIDIA:mainfrom
yatesdr:fix/helios-exact-snapshot-selection
Nov 18, 2026
Merged

yatesdr merged 1 commit into
NVIDIA:mainfrom
yatesdr:fix/helios-exact-snapshot-selection

Conversation

@yatesdr

@yatesdr yatesdr commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #319. Part of #335.

#354 removed the planner's per-waiting-request storage simulations, which multiplied the cost of select_snapshots. It did not change the cost of one call. On nested-alias shapes, which are common under agent traffic with long shared prefixes, one two-row selection takes seconds, and a quote can run several selections. This PR removes that per-call worst case, so #319 stays fixed under heavier shapes than #354 alone handles. It makes each selection exact and cheap: prefix sums over contiguous alias ranges replace per-page postings.

main (with #354) this PR
Two-row selection, nested shape (1,986 aliases, 327,680 pages) 10.23 s 0.84 ms
One-row selection, same shape 14.8 ms 0.88 ms
Selections differing from main (18.05M randomized inputs) — 0
32 cold ~12.7K-token requests, TTFT p50 (DeepSeek-V4.1-Flash TP4, 4x RTX PRO 6000) 29.0 s 28.8 s
#319 agent load, 10 min (12 conversations, ~70K shared prefix, 60% cancelled mid-stream) not run on DeepSeek; GLM-5.3-Flash run pending 210 requests, 0 errors, no wedge; longest no-token gap 70 s, consistent with prefill of ~100K-token prompts

The other proposals for #319, and what happened to each idea:

Remaining follow-up: a quote still re-selects after each eviction (1+E selections), and each selection is now cheap.

Snapshot selection repeatedly walks per-page postings when aliases overlap,
making heavily overlapping cache layouts expensive to select. Each alias
is a validated contiguous page range, so prefix sums can count its free
backing and pairwise overlap exactly.

Replace candidate page vectors and posting lists with free-page and
blocked-page prefix sums. Use an excluded-page bitmap and prefix sum for
larger greedy witnesses, and reject insufficient candidate sets early.
Retain the reference tests and replace the posting-offset helper test
with selection over the same large overlap geometry.

Preserve minimum-cost selection and lowest-ID ties for one or two rows,
and preserve the greedy witness for larger counts, while removing page
work proportional to aggregate pair overlaps. No candidate cap is added.

In a macOS scratch build with platform shims, 310 scheduler tests and both
production-geometry tests passed. Randomized selection matched the
reference in 41,910 comparisons. Main exceeded the nested-alias work bound
with 5,732,032 page visits; the replacement used 256 for two rows.
The production fixture showed no two-row quote-time improvement.

On Linux (rebased on main with NVIDIA#354), scheduler:: and
server::runtime::phase_tests pass 422 tests. An independent comparison of
the compiled select_snapshots from main and from this change matched on
18,054,687 randomized inputs (6.9M feasible), including nested, random
and short-window shapes; eight injected mutations were each caught by the
change's own comparison test. On a nested shape with 1,986 aliases over
327,680 pages, one two-row selection takes 10.23 s on main and 0.84 ms
here; one-row selection takes 14.8 ms and 0.88 ms. On DeepSeek-V4.1-Flash
TP4 (4x RTX PRO 6000), 32 cold ~12.7K-token requests start in 28.8 s
median (main with NVIDIA#354: 29.0 s), and 10 minutes of the NVIDIA#319 agent load
(12 conversations, ~70K shared prefix, 60% cancelled mid-stream) ran 210
requests with no errors and no wedge.

Not tested: TLA+, Kani, and the remaining cost of re-selecting after each
eviction inside one quote (a follow-up).

Design-Signed-Off-By: yatesdr; design-review=ed22
@yatesdr
yatesdr force-pushed the fix/helios-exact-snapshot-selection branch from 90e5552 to 7a1b5ad Compare November 18, 2026 22:01
@yatesdr yatesdr changed the title Count snapshot alias costs with prefix sums Count snapshot alias costs with prefix sums (fixes #319) Nov 18, 2026
@yatesdr
yatesdr merged commit c8d8b67 into NVIDIA:main Nov 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant