Skip to content

Optimize the WFA backend on long (PacBio) reads #51

Description

@cjfields

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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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

  • Add a WFA kernel micro-benchmark (mirror the existing bench_align_vectorized in nwalign.rs) on a fixed long-read pair, to isolate per-alignment cost from the pipeline.
  • Profile a PacBio learn-errors WFA run (e.g. cargo flamegraph) to see where time goes (free-ends exploration vs wavefront compute vs traceback vs allocation).
  • A/B bounded vs full free-ends span; bounded vs BiWFA.
  • Re-enable the PacBio WFA concordance gate in concordance.yml once WFA is competitive (it is deliberately deferred in Experimental WFA alignment backend (wfa2lib-rs), opt-in via --align-backend (#49) #50).

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions