Skip to content

diskgraph: compute offset chunk positions instead of a per-process directory - #93

Merged
Vedaant-J merged 1 commit into
mainfrom
vedaant/diskgraph-shared-chunk-directory
Oct 22, 2026
Merged

Vedaant-J merged 1 commit into
mainfrom
vedaant/diskgraph-shared-chunk-directory

Conversation

@Vedaant-J

@Vedaant-J Vedaant-J commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR removes the per-process offset chunk directory from DiskGraph's ShardReader. Each sampler process used to build a private heap copy of it; on a 50B-node index that copy was ~19 GiB per process.

Problem. On large indexes, the number of sampler processes a host can run is limited by memory, not by cores:

  • How many SamplerEngine processes fit on one host, and can sampling use all of its cores?
  • Why does each process use ~19 GiB of private memory when the index files are memory-mapped and shared through the page cache?

On a 50B-node index (7 node types × 171 shards, 101 GiB of offsets.bin), each process held ~20 GiB of anonymous memory after open. On a 128-vCPU / 991 GiB host, 32 processes ran out of memory at 2 hops. Threads inside one process do not add throughput past ~1.5 busy cores, so the host could not be filled.

Cause. offsets.bin stores node offsets in delta-packed chunks: [u16 count][u64 base][(count-1) × delta_bytes], 64 offsets per chunk. ShardReader::open scanned every chunk and pushed an OffsetChunk { base_idx: u64, count: u16, data_offset: usize } (24 B) into a Vec per shard, to find a node's chunk later. That is one 24-byte entry per 64 nodes, or 50B / 64 × 24 B ≈ 18.7 GB per process, and every process built its own copy. Open also read every page of offsets.bin to build it.

Change. The writer always emits full 64-offset chunks; only the last one can be partial. The reader already relied on this (it indexed the directory with idx / 64). A chunk's byte position is therefore fixed:

chunk_pos(i) = header_len + i × (2 + 8 + 63 × delta_bytes)

decode_offset now computes the position instead of looking it up, then decodes exactly as before. The directory, its build loop and its memory are gone. Open no longer scans offsets.bin.

The per-lookup checks are kept: a chunk past the end of the file is still offset chunk missing, an index outside the chunk's stored count is still offset chunk range mismatch, and every delta read is still bounds-checked.

No file changes on disk: same offsets.bin, same layout version, no new files, nothing new in _MANIFEST.json, no re-ingest.

Alternatives considered

Option Memory per process (50B) On-disk change Verdict
Before: heap Vec<OffsetChunk> ~19 GiB none —
Compact in-memory directory (u32/u64 positions only) ~3–6 GiB none still per process, still scans at open
Sidecar offsets.chunks file, mmapped and shared ~0 private (page cache) new file per shard, manifest/export/integrity changes, build-on-first-open for old indexes adds a derived artifact that duplicates information already implied by the format
Computed positions (this PR) 0 none chosen

Back-compat

Situation Behaviour
Index built before this PR Read as-is. Same offsets, same edge slices, no rebuild.
Index built after this PR, read by an older engine Identical files, so identical behaviour.
Snapshot export / restore, integrity check Unchanged: no new files.
Truncated offsets.bin Same indexes fail with the same errors as before (tested). The error still surfaces on lookup, not at open.
offsets.bin whose chunks aren't 64 offsets (no DiskGraph writer produces this) Chunk 0 behaves as before. Later lookups are still checked against the stored chunk count, but no longer against a start index found by scanning.

Measured results

Index: a synthetic relational graph with 50B nodes in 7 node types, 171 shards per type, 2.6 TiB on disk, of which offsets.bin is 101 GiB. Workload: temporal most-recent sampling for 2 to 6 hops plus a feature fetch for every sampled node, run by P independent processes of T sampler threads each. Old build and this PR are the same commit apart from this change.

Machine A: 128 vCPU, 991 GiB RAM, 8 local NVMe SSDs striped (28 TB). Machine B: 192 vCPU, 1.5 TiB RAM, local NVMe.

Per process, after SamplerEngine open (machine A)

Old This PR
Anonymous memory 20.11 GiB 2.65 GiB
Open time, page cache warm 28.0 s 1.35 s
Open time, page cache dropped 40.4 s 2.4 s
Bytes read during open, page cache dropped 102.9 GiB (all of offsets.bin) 3.7 GiB
Anonymous memory while sampling ~20 GiB ~2.9 GiB (188 GiB summed over 64 processes)

How many processes fit. With the old build, 32 processes at 2 hops ran the 991 GiB machine out of memory, and 32 processes at 2–4 hops evicted the index from the page cache (10–17 GB re-read per warm pass). Its best configs used 24–32 processes. With this PR, 128 processes ran at 6 hops with ~320 GiB used.

Correctness. 300 seeds at 2 and 6 hops, sampled rows plus fetched keys, old build vs this PR: every table has the same rows. Tables whose row order is stable from run to run (5 of 7) are byte-identical. In the other two the row order differs between old and new, but it differs just as much between two runs of the old build, and between two runs of this PR. That ordering is pre-existing nondeterminism, not this change.

Warm throughput (seeds/s), best config per hop. Each cell is a warm-up pass and then a measured pass over the same seeds; measured passes read 0 bytes from disk. Latency is per batch within one process.

hops Old, machine A This PR, machine A p50 / p99 per batch, old → this PR This PR, machine B
2 228,402 (24×8, batch 2048) 299,672 (64×4) 0.19 / 0.23 s → 0.39 / 0.52 s 421,042 (64×3)
3 57,487 (24×8, 1024) 100,782 (64×4) 0.36 / 0.45 s → 0.55 / 0.77 s 143,935
4 30,428 (24×8, 512) 54,093 (64×4) 0.34 / 0.43 s → 0.52 / 0.64 s 77,316
5 4,231 (32×8, 128) 6,966 (128×1) 0.85 / 1.05 s → 1.68 / 2.30 s 10,919
6 2,695 (32×8, 64) 4,467 (96×1, 256) 0.65 / 0.87 s → 3.43 / 5.55 s 6,582 (96×2)

The speedup (1.3× at 2 hops, 1.65–1.8× at 3–6 hops on machine A) comes from running more processes, which memory no longer prevents. Per-batch latency rises because the best configs use fewer threads per process. At 6 hops with batch 64 this PR does 4,302 seeds/s at p50 1.22 s / p99 1.67 s. The old build's config shapes still run with their old latency.

Cold reads. With the page cache dropped, a 1M-seed 2-hop pass reads 300 GB with this PR and 200 GB with the old build. The difference is offsets.bin: the old build read all of it during open, outside the timed pass. With offsets.bin pre-read, this PR's cold pass reads 200.4 GB, the same as the old build. The process count does not change it: 16×8 and 64×2 both read 299.6 GB. During cold passes the SSDs serve ~0.75M reads/s at 0.16 ms, with outstanding I/O roughly equal to the number of sampler threads. Cold sampling is bound by synchronous page-fault latency, not by device bandwidth (a 4 KiB random-read benchmark on the same volume reaches 2.3M IOPS).

Known limitations

  • About 2.7 GiB per process is still private memory; this PR does not look into it.
  • Threads inside one process still stop adding throughput beyond 1.8–2.6 busy cores at 6 hops. The rayon workers are asleep about 85% of the time, so this is serial per-request work, not lock contention or the Python GIL. Scale with processes, as above.
  • The warm numbers assume the sampled neighbourhood stays in the page cache. A cold 6-hop pass over 450k distinct seeds touched 845 GB, more than machine A's page cache.

Testing Done

  • New diskgraph-index/src/tests_reader.rs, which keeps the previous directory-based decoder as a reference:
    • every offset on random shards of 1, 2, 63, 64, 65, 127, 128, 129, 191, 4096, 5000 and a random 1–20,000 offsets (this covers a partial last chunk), for delta widths 2, 3 and 4, with deltas of 0, the width's maximum, and random values. Results match both the reference decoder and the source offsets;
    • truncated offsets.bin (cut inside the header region, inside a chunk header, at a chunk boundary, mid-file, one byte short): the same indexes succeed or fail as with the reference;
    • ShardReader::edges_for_node returns the same edge-blob slice as the source offsets for every node, for each width.
  • New pybind test test_offset_chunks.py: ingests a 1,000-node table (16 chunks, the last one partial) at delta widths 2, 3 and 4, then fetch_features for every node and checks each row's values.
  • 50B index on machine A: sampled rows identical to the old build at 2 and 6 hops (see Measured results).
  • cargo test -p diskgraph-index, -p diskgraph-engine, -p diskgraph-gateway pass. cargo clippy -p diskgraph-index -p diskgraph-engine --all-targets -D warnings is clean. The full pybind suite against the built manylinux wheel passes (260 passed, 3 skipped).

Change map: see the kumo-pr-change-map comment.

Checklist

  • No breaking changes.
  • Unit tests added.

🤖 Generated with Claude Code

…rectory

ShardReader::open scanned every offsets.bin chunk into a heap
Vec<OffsetChunk> (24 B per 64 offsets). On a 50B-node index that is
~19 GiB of private memory per sampler process, which capped the number
of processes a host could run.

Chunks are fixed-size (64 offsets, last one partial), so a chunk's byte
position is header_len + chunk_idx * (10 + 63 * delta_bytes). Look it up
directly and keep the same per-lookup bounds and range checks. No change
to the on-disk format.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Vedaant-J

Copy link
Copy Markdown
Contributor Author

Change map

File Function / scope What changed Why
packages/diskgraph/diskgraph-index/src/reader.rs ShardReader, decode_offset, locate_chunk Dropped OffsetChunk, parse_offset_chunks and find_chunk; the reader keeps header_len and computes a chunk's byte position from its index; same bounds and range checks Removes the ~19 GiB per-process heap directory at 50B nodes and the full offsets.bin scan at open
packages/diskgraph/diskgraph-index/src/lib.rs test modules Registers tests_reader New tests
packages/diskgraph/diskgraph-index/src/tests_reader.rs new tests Old directory-based decoder kept as a reference; equivalence on random shards for widths 2–4, truncated files, and edges_for_node slices Proves byte-identical offsets and identical error behaviour
packages/diskgraph/diskgraph-pybind/python/tests/test_offset_chunks.py new pybind test Ingests a 1,000-node table at delta widths 2, 3 and 4 and checks fetch_features for every node End-to-end check through the wheel's ingest and SamplerEngine

@copy-pr-bot

copy-pr-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

📝 Walkthrough

ShardReader now stores the offsets header length instead of a parsed chunk directory. Offset decoding calculates chunk positions from the header length, delta width, and DELTA_CHUNK, and validates chunk availability and index ranges. New Rust tests compare decoding, truncation handling, and edge slicing with legacy behavior. A Python integration test checks feature fetching across offset chunks.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to f9741

Files encoded with a different chunk width can return incorrect edge data. Validate the persisted width before merging, or explicitly accept this bounded compatibility risk.

Pre-merge checks: Passed 2 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Change Map Design Review Inconclusive The required PR conversation comment beginning with <!-- kumo-pr-change-map --> is unavailable. The repository contains only the template and checker, and the supplied context contains a summary of … Provide the full marked PR conversation comment, including its Change map and rationale, or enable PR conversation access. Then compare it with the authoritative four-file diff and the repository behavior.
Passed Passed checks: 2 passed
Check name Status Explanation
Pr Size Passed The pull request changes 4 files. This count does not exceed 40.
Public Resource Access Passed The pull request adds no external URL, repository location, or package source location. The added references are local module imports, local temporary paths, local fixture filenames, and the local `ca…
Full details: Public Resource Access

Explanation

The pull request adds no external URL, repository location, or package source location. The added references are local module imports, local temporary paths, local fixture filenames, and the local cargo test command. No public-access verification is required.

Full details: Change Map Design Review

Explanation

The required PR conversation comment beginning with &lt;!-- kumo-pr-change-map --&gt; is unavailable. The repository contains only the template and checker, and the supplied context contains a summary of the comment rather than its actual Change map and required rationale. Therefore I cannot verify each proposed scope, necessity, stopping condition, or focused verification against the required comment.

Resolution

Provide the full marked PR conversation comment, including its Change map and rationale, or enable PR conversation access. Then compare it with the authoritative four-file diff and the repository behavior.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note

Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.

🟡 Other comments: 1
packages/diskgraph/diskgraph-index/src/reader.rs: 1

248-251: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Reject persisted chunk widths that arithmetic lookup cannot decode.

OffsetFileHeader::delta_chunk is persisted, but locate_chunk always uses DELTA_CHUNK (64). A file encoded with another chunk width can pass ShardReader::open; the previous reader used each stored chunk count and could decode it, while the current reader can compute later chunk positions incorrectly.

Suggested fix
         if !matches!(header.node_data_len_bytes, 2..=4) {
             return Err(
                 DiskgraphError::InvalidMetadata("node data len width invalid".into()).into(),
             );
         }
+        if header.delta_chunk as usize != DELTA_CHUNK {
+            return Err(
+                DiskgraphError::InvalidMetadata("offset delta chunk size invalid".into()).into(),
+            );
+        }
         let edge_count = header.edge_count;

Do not add exact mapped-file length rejection as part of this fix. The previous reader allowed truncated files to open, and the truncation tests preserve lookup-time errors.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/kumo-engine/.coderabbit.yaml
  • Review profile: QUIET
  • Plan: Enterprise
  • Run ID: eb648338-5a6b-4d6b-9fb1-05fb1d2d4cfd
📥 Commits

Reviewing files that changed from the base of the PR and between bdb6294 and f97414f.

📒 Files selected for processing: 4
  • packages/diskgraph/diskgraph-index/src/lib.rs
  • packages/diskgraph/diskgraph-index/src/reader.rs
  • packages/diskgraph/diskgraph-index/src/tests_reader.rs
  • packages/diskgraph/diskgraph-pybind/python/tests/test_offset_chunks.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.

@Victsm Victsm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed the fixed-size offset lookup against the existing writers and legacy reader. No correctness blocker found; 57 Rust index tests passed. The remaining connector CI failure is due to missing restricted BigQuery test identities. Large-scale memory/throughput A/B validation remains outstanding.

@Vedaant-J
Vedaant-J merged commit 3100e71 into main Oct 22, 2026
111 of 112 checks passed
@Vedaant-J
Vedaant-J deleted the vedaant/diskgraph-shared-chunk-directory branch October 22, 2026 00:25
Vedaant-J added a commit that referenced this pull request Oct 27, 2026
## Summary

This PR makes **DiskGraph sampling output reproducible**: the same
request with the same `random_seed` now returns the same local node ids
and the same edge order every time.

**Problem.**
- Two runs of the same sampling request return the same set of nodes and
edges but in a different order, with different local ids. A run cannot
be compared row by row with an earlier one, and a regression test cannot
pin an exact output.
- At 50B (#93), 2 of 7 sampled tables changed row order between two runs
of the same build.

**Cause.** In each layer, `process_layer` builds its work queue by
iterating `SamplingState::type_states`, a `gxhash` map; the fused path's
final feature flush iterates the same map. Its hasher is randomly seeded
per map instance, so each pooled or fresh `SamplingState` iterates node
types in a different order. When more than one node type is on the
frontier, as in every layer after the first in a heterogeneous graph,
the type processed first gets the lower local ids for the destinations
they share, and its edges are emitted first.

**Change.** The work queue and the fused path's final feature flush are
both processed in node type id order. Nothing else changes.

## Back-compat

| Situation | Behaviour |
|---|---|
| Same request, same seed, repeated | Identical output (previously
varied between states). |
| Output compared with a run of an older build | Same nodes and edges
per seed; local ids and edge order match one of the orders the older
build could already produce. |
| Single node type on the frontier | Unchanged. |
| Fused feature-fetching path | Sampling and the final feature flush in
type-id order; fused feature batches arrive in the same order every run.
|

## Testing Done

- New `repeated_runs_give_identical_output`: two node types that both
reach the same destination type in one hop; 16 fresh states per run,
fused and non-fused; edges, node records and fused feature batches must
be identical. It fails on `main`, and also fails if only the flush is
left unsorted.
- On 100M- and 1B-row synthetic indexes, 6 batches of 512 seeds at 2–6
hops gave identical edges, nodes, frontiers and stats across fresh
states (part of the stacked PR's real-graph test).
- `cargo test -p diskgraph-engine --lib` passes; clippy is clean on the
changed code.

## Checklist
- [x] No breaking changes.
- [x] Unit tests added.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Vedaant-J added a commit that referenced this pull request Oct 28, 2026
…uest (#102)

Stacked on #101 (`vedaant/dg-per-seed-recording`).

## Summary

This PR **runs the per-seed deduplication on the sampler's thread pool**
and **resolves seed anchor times once per request**. Together with the
previous PR, multi-threaded sampling is 2–3.3× faster than `main` at 3–6
hops, with identical output.

**Problem.** After the previous PR, a process with 8 sampler threads
still spent most of a 5–6-hop request in serial work, and one per-edge
lookup remained in the parallel phase:
- With 8 threads at 5 hops, the commit phase took 6.6 s of a 7.3 s run
(100M graph, 5,000 seeds), with about 2.3 cores busy.
- Every sampled (node, relation) pair looked up its seed's anchor time
by hashing the seed type's name string, about 8% of single-thread CPU.

**Cause.** The per-seed step only touches one seed's map and edges, but
it ran on one thread. The anchor lookup went `seed_type_id → type name →
HashMap<String, Vec<i64>>` on every call to `sample_segment_edges`.

**Change.**
- `commit_edges` splits the seeds into contiguous ranges of roughly
equal edge counts (4 per thread) and runs the deduplication and the
final map update on the engine's pool. Local id assignment and edge
output remain one in-order pass, so output is unchanged. The parallel
path runs only when the pool has more than one thread and the layer has
at least `DiskGraphEngine::parallel_commit_min_edges` edges (default
32,768); single-thread processes run the same code inline. The default
comes from forcing the threshold to 1 and to infinity at 8 threads:
layers of a few thousand to ~25k edges ran 10–50% slower on the pool,
layers of 100k+ edges ran faster. Cuts fall on seed boundaries, so
ranges are uneven; 4 ranges per thread let the pool balance them.
- The in-order pass keeps each destination type's state at hand instead
of looking it up in `type_states` for every new node.
- `sample_with_cutoff` resolves each seed type's anchor slice once;
`sample_segment_edges` takes that slice table instead of the request.

## Back-compat

| Situation | Behaviour |
|---|---|
| Standalone sampling, any thread count | Same local ids, edges,
frontiers and stats as the previous path (tested at 4 threads). |
| 1-thread process | No parallel dispatch; same code inline. |
| Fused feature-fetching sampling | Anchor change only; output
unchanged. |
| `legacy_recording = true` | Previous path. |
| `parallel_commit_min_edges` | New public engine field; only changes
when the parallel dedup runs, never the output. |

## Measured results

Same indexes, workload, ctxbench-style driver and machine as the
previous PR. Sampling seeds/s, better of two interleaved rounds:

| graph | threads | hops | `main` | previous PR | this PR | this PR /
`main` | with feature fetch, `main` → this PR | cores busy, `main` →
this PR | p99 per batch, `main` → this PR |
|---|---|---|---|---|---|---|---|---|---|
| 100M | 1 | 2 | 36,496 | 31,250 | 35,211 | 0.96× | 18,587 → 17,794 |
1.0 → 1.0 | 30 → 29 ms |
| 100M | 1 | 3 | 7,899 | 9,960 | 10,846 | 1.37× | 5,123 → 6,090 | 1.0 →
1.0 | 107 → 85 ms |
| 100M | 1 | 4 | 2,836 | 3,213 | 4,340 | 1.53× | 2,094 → 2,769 | 1.0 →
1.0 | 250 → 191 ms |
| 100M | 1 | 5 | 331 | 578 | 648 | 1.96× | 270 → 435 | 1.0 → 1.0 | 1.95
→ 1.23 s |
| 100M | 1 | 6 | 154 | 226 | 269 | 1.74× | 138 → 222 | 1.0 → 1.0 | 3.82
→ 2.44 s |
| 100M | 8 | 2 | 51,546 | 53,191 | 56,180 | 1.09× | 27,778 → 28,902 |
3.1 → 3.2 | 19 → 18 ms |
| 100M | 8 | 3 | 9,804 | 12,987 | 19,685 | 2.01× | 7,728 → 13,021 | 2.5
→ 3.2 | 67 → 41 ms |
| 100M | 8 | 4 | 4,444 | 5,359 | 8,865 | 1.99× | 3,771 → 6,831 | 2.6 →
3.5 | 139 → 82 ms |
| 100M | 8 | 5 | 421 | 704 | 1,268 | 3.01× | 393 → 1,041 | 1.8 → 3.2 |
1.34 → 0.52 s |
| 100M | 8 | 6 | 235 | 397 | 630 | 2.68× | 225 → 563 | 1.9 → 3.1 | 2.38
→ 1.00 s |
| 1B | 1 | 2 | 30,675 | 27,473 | 30,303 | 0.99× | 15,385 → 15,773 | 1.0
→ 1.0 | 34 → 33 ms |
| 1B | 1 | 3 | 6,821 | 8,913 | 9,980 | 1.46× | 4,355 → 5,556 | 1.0 → 1.0
| 125 → 99 ms |
| 1B | 1 | 4 | 2,900 | 3,183 | 3,843 | 1.33× | 2,033 → 2,449 | 1.0 → 1.0
| 266 → 224 ms |
| 1B | 1 | 5 | 327 | 554 | 612 | 1.87× | 262 → 418 | 1.0 → 1.0 | 2.12 →
1.33 s |
| 1B | 1 | 6 | 162 | 236 | 282 | 1.74× | 142 → 228 | 1.0 → 1.0 | 3.85 →
2.39 s |
| 1B | 8 | 2 | 48,544 | 48,077 | 53,191 | 1.10× | 25,253 → 26,455 | 3.7
→ 3.8 | 21 → 20 ms |
| 1B | 8 | 3 | 9,634 | 13,587 | 19,455 | 2.02× | 7,396 → 12,255 | 2.8 →
3.6 | 73 → 46 ms |
| 1B | 8 | 4 | 4,651 | 5,525 | 8,000 | 1.72× | 3,975 → 5,995 | 2.5 → 3.8
| 133 → 89 ms |
| 1B | 8 | 5 | 402 | 716 | 1,334 | 3.32× | 374 → 1,066 | 1.8 → 3.3 |
1.42 → 0.51 s |
| 1B | 8 | 6 | 233 | 407 | 680 | 2.91× | 223 → 593 | 1.9 → 3.5 | 2.39 →
0.92 s |

Four concurrent processes of 8 threads each (aggregate sampling seeds/s;
a scaled-down version of the 16×8 layout used on large hosts, limited by
this shared machine):

| graph | hops | `main` | this PR | × | with feature fetch × | cores
busy, `main` → this PR |
|---|---|---|---|---|---|---|
| 100M | 2 | 197,466 | 241,907 | 1.23× | 1.14× | 12.5 → 12.6 |
| 100M | 3 | 39,897 | 74,313 | 1.86× | 1.60× | 9.6 → 12.7 |
| 100M | 4 | 17,195 | 31,178 | 1.81× | 1.62× | 9.7 → 14.1 |
| 100M | 5 | 1,409 | 4,261 | 3.02× | 2.62× | 6.4 → 10.9 |
| 100M | 6 | 877 | 2,338 | 2.67× | 2.48× | 7.0 → 12.5 |
| 1B | 2 | 191,409 | 218,250 | 1.14× | 1.06× | 13.7 → 14.0 |
| 1B | 3 | 38,287 | 74,560 | 1.95× | 1.58× | 10.3 → 14.2 |
| 1B | 4 | 17,512 | 33,131 | 1.89× | 1.64× | 10.1 → 15.2 |
| 1B | 5 | 1,349 | 4,406 | 3.27× | 2.82× | 6.7 → 13.1 |
| 1B | 6 | 748 | 2,218 | 2.96× | 2.72× | 7.1 → 13.7 |

Peak RSS per process rises by 0.0–0.3 GB over `main`.

### Training path (`sample_runtime_batch`, link prediction)

Same setup as the training-path table in #101: `sample_runtime_batch`
with a fresh `SamplingState` per batch, 1B index, two-tower
link-prediction stage table, b=512 with one engine negative per row
(three seed groups of 512), features skipped unless noted. Per-batch
time, previous path (`legacy_recording = true`) → this PR, better of
three interleaved rounds of 4 batches; identical node counts in every
cell.

| threads | 2 hops | 3 hops | 4 hops | 5 hops | 6 hops |
|---|---|---|---|---|---|
| 2 | 96 → 87 ms (1.10×) | 714 → 470 ms (1.52×) | 1.64 → 1.11 s (1.48×)
| 7.23 → 3.90 s (1.86×) | 16.5 → 9.31 s (1.78×) |
| 8 | 79 → 67 ms (1.17×) | 676 → 371 ms (1.82×) | 1.46 → 0.88 s (1.66×)
| 6.74 → 3.01 s (2.24×) | 14.9 → 7.02 s (2.12×) |

With feature fetch for every sampled node (8 threads): 114 → 101 ms
(1.13×) at 2 hops, 1.89 → 1.28 s (1.48×) at 4 hops.

### 50B index

| Hops | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|
| seeds/s (best config, #102) | 392k | 169k | 98k | 13.8k | 9.3k |
| vs main (best config) | 1.10× | 1.16× | 1.19× | 1.6× | 1.4× |

50B commerce, i7ie.48xlarge, warm, b=512, numa_balancing=0, identical
row counts.

Same published synthetic graph as #93 (49,997M rows, 7 node types × 171
shards, 2.6 TB index). Machine: 192 vCPU, 1.5 TiB RAM, local NVMe,
`kernel.numa_balancing=0`. Harness: P processes × T threads, sampling
plus feature fetch for every sampled node, b=512, warm (a warm-up pass,
then the same seeds measured). `main` and this PR return identical row
counts in every cell.

Seeds/s, `main` → this PR:

| hops | 64×3 | 16×8 | 96×2 |
|---|---|---|---|
| 2 | 273,570 → 374,560 (1.37×)¹ | 200,983 → 219,036 (1.09×) | 356,736 →
392,243 (1.10×) |
| 3 | 118,877 → 161,784 (1.36×) | 61,169 → 84,639 (1.38×) | 146,194 →
169,197 (1.16×) |
| 4 | 70,050 → 92,251 (1.32×) | 29,632 → 44,783 (1.51×) | 81,754 →
97,583 (1.19×) |
| 5 | 7,850 → 13,750 (1.75×) | 3,619 → 6,713 (1.86×) | 8,560 → 11,687
(1.37×) |
| 6 | 5,729 → 8,740 (1.53×) | 2,114 → 4,146 (1.96×) | 6,777 → 9,319
(1.38×) |

Best config per hop:

| hops | `main` | this PR | #93 run, b=512 | #93 run, best config |
DuckDB 2.0 native 8×16 / 8×24 |
|---|---|---|---|---|---|
| 2 | 356,736 | 392,243 | 387,683 (64×3) | 421,042 (64×3) | 37,332 /
42,651 |
| 3 | 146,194 | 169,197 | —² | 143,935 (96×2) | 24,549 / 27,605 |
| 4 | 81,754 | 97,583 | 77,214 (96×2) | 77,316 (96×2) | 15,867 / 15,045
|
| 5 | 8,560 | 13,750 | —² | 10,919 (96×2) | 4,184 / 5,002 |
| 6 | 6,777 | 9,319 | 6,774 (96×2) | 6,582 (96×2) | 3,020 / 3,138 |

¹ `main`'s measured pass still read 6.7 GB from disk in this cell, so
part of the gain is warm-up; 96×2 is the cleaner 2-hop comparison.
² The #93 run measured b=512 only at 2, 4 and 6 hops. Its best-config
column is the 192-vCPU row of #93's table, at batch sizes tuned per hop.

At 6 hops, p99 per batch at 16×8 drops from 4.2 s to 2.1 s.

Each cell above was measured once; repeated runs on this machine type
have shown about 15% run-to-run spread, so the 1.10–1.19× best-config
gains at 2–4 hops are within noise; the 1.4–1.6× gains at 5–6 hops are
clearly real. The gains are smaller than on the 64-vCPU machine because
the best 50B configs run many processes with 2–3 threads each: there the
commit phase is a smaller share and page faults dominate. The 16×8
layout, where commit work is concentrated in fewer processes, gains
1.4–2.0× at 3–6 hops.

## Known limitations

- One seed that holds most of a layer's edges (a hub seed) lands in a
single range, so its dedup runs on one thread and caps the parallel
speedup for that request.
- With 8 threads at 5–6 hops, the remaining serial work is the in-order
id assignment and edge output (about 60% of commit time) and the
counting sort (about 20%).

## Testing Done

- Both equivalence tests from #101 also run with
`parallel_commit_min_edges = 1`, so at 4 threads every multi-seed layer
takes the parallel branch, and compare that run with the previous path.
- `tests/per_seed_recording_real_graph.rs` (4 threads) passes on both
indexes at 2–6 hops.
- `cargo test -p diskgraph-engine`, `-p diskgraph-ingest --test
seed_table_ingest --test resolution_runtime_batch` and `-p
diskgraph-pybind` pass; `cargo clippy --workspace --all-targets -- -D
warnings` is clean.

## Checklist
- [x] No breaking changes.
- [x] Unit tests added.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>

This branch was previously deployed

1 inactive deployment
gha-kumo-workflow-tests — f97414ff Deployed Oct 21, 2026 by Vedaant-J via import #418
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