Follow-up to #49 / #50. The experimental WFA backend (--align-backend wfa2, off by default) is ASV-equivalent to the default NW aligner on both Illumina and PacBio HiFi, but it is slower than NW on long reads, which is the opposite of what WFA should deliver. This issue tracks digging into why and closing the gap.
Measurements so far (PacBio HiFi, ~1472 bp full-length 16S, learn-errors, band 32)
| Variant |
Time |
vs NW |
| NW (default) |
~29 s |
1× |
| WFA, fresh aligner per call |
>6 min (killed, unfinished) |
>13× |
| WFA, cached per-thread aligner ([#50]) |
~124 s |
~4.3× |
Illumina (short reads) shows no meaningful perf difference. The pathology is specific to long reads.
Why this is surprising / worth digging into
WFA's complexity is O(n·s) (length × alignment score), so on similar sequences it should beat NW's O(n·band). The pure-Rust port (COMBINE-lab/wfa2lib-rs) documents parity with — and in some cases (e.g. gap-linear) a slight edge over — the original C++ WFA2-lib. So a >4× slowdown on long reads points at how we're driving it, not the algorithm itself.
Hypotheses to investigate
- Full ends-free free-gap span.
align_wfa_endsfree_with_buf calls set_alignment_free_ends(plen, plen, tlen, tlen) — i.e. the entire sequence length is free at every end. On ~1500 bp reads this may make WFA explore a large free-end space each alignment. A bounded free span (e.g. ~band, matching the amplicon overhang we actually expect) may be much faster — and could also help the known ends-free crediting divergence.
- CIGAR (ComputeAlignment) vs score-only wavefront retention.
ComputeAlignment keeps non-modular wavefronts (all scores alive) for traceback; on long reads that is more memory/time. Check whether the retention/reap_cigar path is the cost.
- BiWFA (
align_biwfa). O(s) memory, designed for long sequences with full traceback. Worth A/B-ing against the plain affine aligner on the PacBio fixture.
- Heuristics off by default. wfa2lib supports adaptive/Z-drop pruning (
set_heuristic). Could speed long reads, but must be validated for ASV-equivalence before use.
- Penalty magnitude / Eizenga scaling. Our Eizenga-adjusted penalties roughly double mismatch/gap internally (
mismatch=18, gap_ext=21 for the default scheme), inflating the score s that drives WFA's work. Worth checking whether a smaller equivalent scheme reduces wavefront growth.
Suggested tasks
Pointers
- Adapter + cached aligner:
src/nwalign.rs (align_wfa_endsfree_with_buf, the thread_local cache).
- Divergence reproducer (related, ends-free):
wfa_diagnose test.
- Default stays
nw, so this is not user-facing-urgent — it gates whether WFA is worth promoting beyond experimental.
Follow-up to #49 / #50. The experimental WFA backend (
--align-backend wfa2, off by default) is ASV-equivalent to the default NW aligner on both Illumina and PacBio HiFi, but it is slower than NW on long reads, which is the opposite of what WFA should deliver. This issue tracks digging into why and closing the gap.Measurements so far (PacBio HiFi, ~1472 bp full-length 16S,
learn-errors, band 32)Illumina (short reads) shows no meaningful perf difference. The pathology is specific to long reads.
Why this is surprising / worth digging into
WFA's complexity is O(n·s) (length × alignment score), so on similar sequences it should beat NW's O(n·band). The pure-Rust port (COMBINE-lab/wfa2lib-rs) documents parity with — and in some cases (e.g. gap-linear) a slight edge over — the original C++ WFA2-lib. So a >4× slowdown on long reads points at how we're driving it, not the algorithm itself.
Hypotheses to investigate
align_wfa_endsfree_with_bufcallsset_alignment_free_ends(plen, plen, tlen, tlen)— i.e. the entire sequence length is free at every end. On ~1500 bp reads this may make WFA explore a large free-end space each alignment. A bounded free span (e.g. ~band, matching the amplicon overhang we actually expect) may be much faster — and could also help the known ends-free crediting divergence.ComputeAlignmentkeeps non-modular wavefronts (all scores alive) for traceback; on long reads that is more memory/time. Check whether the retention/reap_cigarpath is the cost.align_biwfa). O(s) memory, designed for long sequences with full traceback. Worth A/B-ing against the plain affine aligner on the PacBio fixture.set_heuristic). Could speed long reads, but must be validated for ASV-equivalence before use.mismatch=18, gap_ext=21for the default scheme), inflating the scoresthat drives WFA's work. Worth checking whether a smaller equivalent scheme reduces wavefront growth.Suggested tasks
bench_align_vectorizedinnwalign.rs) on a fixed long-read pair, to isolate per-alignment cost from the pipeline.learn-errorsWFA run (e.g.cargo flamegraph) to see where time goes (free-ends exploration vs wavefront compute vs traceback vs allocation).concordance.ymlonce WFA is competitive (it is deliberately deferred in Experimental WFA alignment backend (wfa2lib-rs), opt-in via --align-backend (#49) #50).Pointers
src/nwalign.rs(align_wfa_endsfree_with_buf, thethread_localcache).wfa_diagnosetest.nw, so this is not user-facing-urgent — it gates whether WFA is worth promoting beyond experimental.