Skip to content

perf(bwt): prefetch the first backward-extension occ blocks after a k-mer lookup - #65

Merged
lh3 merged 1 commit into
masterfrom
perf/smem-prefetch-occ
Aug 8, 2026
Merged

perf(bwt): prefetch the first backward-extension occ blocks after a k-mer lookup#65
lh3 merged 1 commit into
masterfrom
perf/smem-prefetch-occ

Conversation

@nh13

@nh13 nh13 commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

mb_bwt_smem_batch() already prefetches occ blocks for every in-flight backward and forward extension step, but the stage 2/5 k-mer-cache lookup is a gap: seeding the interval from bwt->pre, and the mb_bwt_set_intv() revert, both leave the occ array untouched, so the first backward extension in stage 3/6 starts on cold blocks.

This issues the two prefetches that step will need — x[0] and x[0]+size, the addresses mb_bwt_extend() reads for a backward step — at the end of the lookup stage, so the lines arrive while the entry travels back through the queue. It follows the pattern the four existing prefetch sites already use. Six lines, no new helper, no logic change.

Output is unchanged — SAM byte-identical on 100k HG002 WGS pairs.

Mapping-phase wall clock, c8g.4xlarge (Graviton4, 16 vCPU, gcc 11.5), -t 16, hs38 with ALT contigs, 5 interleaved reps with build order reversed between reps, per-rep spread 0.29–0.37%:

dataset before after
1kg HG00096 WGS, 5M pairs 41.236s 40.832s −1.0%
1kg HG00100 WES, 5M pairs 18.700s 18.222s −2.6%

The exome gain is the larger of the two, which is what a prefetch fix in the SMEM walk should do: exome spends a bigger share of its time there (~37% of compute self-time vs ~27% for WGS in a sampling profile), so the same per-lookup saving is a bigger fraction of the total.

…-mer lookup

mb_bwt_smem_batch() already prefetches occ blocks for every in-flight backward
and forward extension step, but the stage 2/5 k-mer-cache lookup is a gap:
seeding the interval from bwt->pre, and the mb_bwt_set_intv() revert, both leave
the occ array untouched, so the first backward extension in stage 3/6 starts on
cold blocks.

Issue the two prefetches the upcoming step will need -- x[0] and x[0]+size, the
addresses mb_bwt_extend() reads for a backward step -- at the end of the lookup
stage, so the lines arrive while the entry travels back through the queue. This
follows the pattern the four existing prefetch sites already use.

Output is unchanged: SAM is byte-identical on 100k HG002 WGS pairs.

Mapping-phase wall clock against this commit's parent, c8g.4xlarge (Graviton4,
16 vCPU, gcc 11.5), -t 16, hs38 with ALT contigs, 5 interleaved reps with the
build order reversed between reps, per-rep spread 0.29-0.37%:

  1kg HG00096 WGS, 5M pairs   41.236s -> 40.832s   -1.0%
  1kg HG00100 WES, 5M pairs   18.700s -> 18.222s   -2.6%

The exome gain is the larger of the two, which is what a prefetch fix in the
SMEM walk should do: exome spends a bigger share of its time there (~37% of
compute self-time versus ~27% for WGS in a sampling profile), so the same
per-lookup saving is a bigger fraction of the total.
@lh3
lh3 merged commit c42d875 into master Aug 8, 2026
4 checks passed
nh13 added a commit to nh13/minibwa that referenced this pull request Aug 8, 2026
lh3#65 merged as c42d875, so master carries the occ-block prefetch and
merging the feature branch on top is now an empty diff. Per "Removing a feature"
the block is deleted rather than marked: the parser rejects `merged`/`superseded`
exactly so a graduated block cannot linger and produce a duplicate-application
conflict, an optional drop and a nightly issue forever.

The weekly reconciler would normally open this deletion itself, but it keys on the
PR number in the block and this one recorded `unsubmitted`. The PR was opened from
a separate r421-based branch (perf/smem-prefetch-occ) rather than the frozen feature
branch, so there was no number here for it to notice going merged. A comment in the
manifest records that, since the same split will happen again the next time a
feature is offered upstream from a rebased copy.

No GRAVEYARD entry: that file is for `[[withdrawn]]` ideas that were investigated
and disproven, and this one graduated.

Verified on the new base c42d875: 14 features assemble with zero drops, the build
still contains both prefetch sites (now from upstream), and the gate passes with 14
covered.
@nh13
nh13 deleted the perf/smem-prefetch-occ branch August 13, 2026 07:39
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