Skip to content

test(spectrum): harden reseed-neighbor-scan (boundary cases) + collect_wall bench - #49

Merged
nh13 merged 4 commits into
mainfrom
perf/reseed-neighbor-scan-harden
Jun 22, 2026
Merged

test(spectrum): harden reseed-neighbor-scan (boundary cases) + collect_wall bench#49
nh13 merged 4 commits into
mainfrom
perf/reseed-neighbor-scan-harden

Conversation

@nh13

@nh13 nh13 commented Jun 18, 2026

Copy link
Copy Markdown

Stacked on #48 (perf/reseed-neighbor-scan). Tests + benchmarking only — no production-code change.

What

  • Deterministic neighbor-scan boundary cases (forward_truncate_boundary_cases). An adversarial review of the neighbor-LCP scan flagged three reasoned-correct but unexecuted branches; the random corpus is statistically unlikely to hit them. This locks them:
    • lmax == 1lcap = 0 → zero (nothing to truncate below a length-1 maximal).
    • SA-end exhaustion: min_intv larger than any achievable occ, so the scan walks both neighbours off the SA ends and breaks on llo == 0 && lhi == 0 → zero (the genuine exhaustion path, not the lmax cap).
    • Both want_interval modes, plus an oracle cross-check.
  • collect_wall — a per-read collect_smems wall-clock harness (ns/read), so the neighbor-scan win can be measured at two commits on a large reference.

Why / evidence

Built at this base vs the pre-scan commit and measured on a Graviton c8g (128 Mbp synthetic reference, 3.49 GB suffix array):

  • Probes (deterministic, byte-identical output): total SA probes/read 1134.9 → 502.2 (-56%); reseed phase -81%.
  • Wall (c8g, 5 interleaved pairs): 35717 → 30468 ns/read = +14.7% (14.62-14.76%).

The adversarial review verdict on the scan itself: byte-identity-sound, nothing blocks merge. This PR just closes the boundary-test gaps and adds the measurement harness.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a Rust benchmark example to measure wall-clock per-read performance for collect_smems, with configurable runtime parameters via environment variables.
  • Improvements

    • Improved spectrum query truncation logic to limit unnecessary scanning and better cap work near the truncation point.
  • Bug Fixes / Tests

    • Added repeat-focused correctness tests and regression guards that verify expected probe counts and validate results against a naive oracle.

nh13 added 3 commits June 16, 2026 14:29
…ts corpus

Replace the O(lmax-L*) per-length walk in forward_truncate_below_maximal with
an O(min_intv) neighbor-LCP scan: read the LCP of the query with the SA suffixes
just outside the interval and extend the larger-LCP side until occ>=min_intv,
then recover the exact interval via find_boundary (span-only for want_interval=false).

Byte-identical to the old walk / naive oracle, proven by the existing
forward_truncate_below_maximal_equals_oracle proptest plus a new repeats/ties
corpus test exercising shared-L* ties and occ(maximal) in [2,min_intv), both
want_interval modes. Probe budget on long-unique reads: 264 -> 18.
Adversarial review of the reseed-neighbor-scan flagged three reasoned-correct but
unexecuted branches. Add forward_truncate_boundary_cases covering: (a) lmax==1
(lcap=0 -> zero), and (b) SA-end exhaustion where min_intv exceeds any achievable
occ, so the scan walks both neighbours off the SA ends and breaks on
llo==0 && lhi==0 -> zero (not via the lmax cap). Both modes (want_interval
true/false) and an oracle cross-check. No production-code change.
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b1819c88-676b-49d9-9238-04c1acb713e7

📥 Commits

Reviewing files that changed from the base of the PR and between 7e292b1 and 7aab436.

📒 Files selected for processing (1)
  • prmi/examples/collect_wall.rs

Walkthrough

Replaces two O(lmax−L*) walk-down loops in spectrum.rs (span_rc_walk and forward_truncate_below_maximal) with neighbor-LCP boundary scans capped at min_intv, adds a deterministic repeat corpus, oracle sweep tests, and probe-count regression guards. Adds a new collect_wall.rs example that wall-clock benchmarks collect_smems.

Changes

Neighbor-LCP scan rewrites in spectrum.rs

Layer / File(s) Summary
RC span and forward truncation neighbor-LCP rewrites
prmi/src/index/spectrum.rs
span_rc_walk drops the iterative expand loop for a capped neighbor-LCP scan at lo-1/hi. forward_truncate_below_maximal hoists the full-32 query key, scans lcp_at at neighbors, and calls find_boundary only when want_interval is true.
repeat_corpus, oracle tests, probe-count regression guards
prmi/src/index/spectrum.rs
repeat_corpus() generates a repeat-heavy deterministic reference. forward_truncate_boundary_cases covers lmax==1 and SA-end exhaustion. forward_truncate_equals_oracle_on_repeats_both_modes sweeps (start, qlen, min_intv) for both modes. forward_truncate_is_o_min_intv_not_o_lmax and span_rc_is_o_min_intv_not_o_span assert probe counts stay bounded under the spectrum-probe-count feature gate.

Wall-clock benchmark harness

Layer / File(s) Summary
collect_wall benchmark harness
prmi/examples/collect_wall.rs
Documentation and env-var helpers establish setup infrastructure. main opens the learned index and FASTQ file, encodes reads to 2-bit representation, runs a warm-up pass with buffer-resize retry, then times PRMI_REPEAT passes and reports min/median/mean ns/read to stderr with median to stdout.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • fg-labs/prmi#48: Directly modifies the same two functions (span_rc_walk / forward_truncate_below_maximal) in spectrum.rs, replacing walk-down loops with neighbor-LCP scans — likely the immediate predecessor of this PR.
  • fg-labs/prmi#27: Introduces mem_search_backward_truncated_span_rc and the min_intv-truncated backward RC span logic that the span_rc_walk refactor in this PR follows.
  • fg-labs/prmi#20: Adds the thread-local SA-probe counter feature (spectrum-probe-count) that gates the probe-count regression tests added here.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main changes: test hardening for spectrum's neighbor-scan implementation (boundary cases) and the new collect_wall benchmark harness.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/reseed-neighbor-scan-harden

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Base automatically changed from perf/reseed-neighbor-scan to main June 20, 2026 17:49
@nh13

nh13 commented Jun 20, 2026

Copy link
Copy Markdown
Author

@coderabbitai resume

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
✅ Action performed

Reviews resumed.

@nh13

nh13 commented Jun 20, 2026

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented Jun 21, 2026

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented Jun 21, 2026

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented Jun 21, 2026

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@prmi/examples/collect_wall.rs`:
- Around line 30-35: The envu function currently treats unparseable environment
variables the same as unset variables by using and_then with unwrap_or, silently
falling back to defaults instead of alerting users to invalid input. Modify the
envu function to distinguish between missing and invalid environment variables:
if std::env::var returns Ok but the parse fails, print an error message to
stderr and exit the process with a non-zero code, otherwise if the variable is
unset return the default value, and if it parses successfully return the parsed
value.
- Around line 53-56: The FASTQ parsing loop starting at lines 53-56 is silently
discarding errors and stopping when records are malformed or truncated, which
allows benchmarking incomplete data. Fix this by validating that all 4 required
FASTQ lines per record (header, sequence, plus line, and quality) are
successfully read: replace the current pattern of using let Some(Ok(...)) else {
break } and let _ = lines.next() with explicit expect() calls on each
lines.next() call so that any missing or error lines will cause the program to
fail immediately rather than continuing with partial records. This ensures the
loop fails closed on any malformed input or read errors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5d3df54e-b0dd-4ae8-b89f-3658c6d35152

📥 Commits

Reviewing files that changed from the base of the PR and between ff13d02 and b078d78.

📒 Files selected for processing (2)
  • prmi/examples/collect_wall.rs
  • prmi/src/index/spectrum.rs

Comment thread prmi/examples/collect_wall.rs
Comment thread prmi/examples/collect_wall.rs Outdated
@nh13
nh13 force-pushed the perf/reseed-neighbor-scan-harden branch from b078d78 to 7e292b1 Compare June 21, 2026 19:29
@nh13

nh13 commented Jun 22, 2026

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented Jun 22, 2026

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@prmi/examples/collect_wall.rs`:
- Around line 47-48: Add validation after reading the pac file to ensure its
length matches the expected size for the given l_pac value. After the line where
pac is read using std::fs::read with the PRMI_PAC path, insert an assertion or
validation check that pac.len() equals (l_pac + 3) / 4. This validation must
occur before creating the PacEncoding::Packed struct to prevent panics or silent
data corruption from truncated or oversized pac files.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4f692912-d523-4900-ad98-8f187cd7acba

📥 Commits

Reviewing files that changed from the base of the PR and between b078d78 and 7e292b1.

📒 Files selected for processing (1)
  • prmi/examples/collect_wall.rs

Comment thread prmi/examples/collect_wall.rs
Times the full per-read SMEM driver (ns/read) over a FASTQ; built at two commits
(pre/post #48) it measures the reseed-neighbor-scan wall win on a large ref.
@nh13
nh13 force-pushed the perf/reseed-neighbor-scan-harden branch from 7e292b1 to 7aab436 Compare June 22, 2026 03:51
@nh13

nh13 commented Jun 22, 2026

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented Jun 22, 2026

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13
nh13 merged commit 2951b07 into main Jun 22, 2026
4 checks passed
@nh13
nh13 deleted the perf/reseed-neighbor-scan-harden branch June 22, 2026 15:35
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.

1 participant