Skip to content

Optimize transformSequences for ~3.5x SHW performance#241

Open
tomck-0 wants to merge 1 commit into
Martinsos:masterfrom
tomck-0:tc/shw-opt-polish
Open

Optimize transformSequences for ~3.5x SHW performance#241
tomck-0 wants to merge 1 commit into
Martinsos:masterfrom
tomck-0:tc/shw-opt-polish

Conversation

@tomck-0

@tomck-0 tomck-0 commented Jul 6, 2026

Copy link
Copy Markdown

I noticed SHW was taking a long time with large queries, and the profiler showed all the time was spent in transformSequences.

I vectorized transformSequences with AVX2 and got about a 3.5x performance improvement for my case. The core optimization is moving the letterIdx lookup table into SIMD registers and using vpshufb to query 32 bytes against the LUT at once.

I moved the old transformSequences function to transformSequencesScalar in the new edlib_util.h alongside the SIMD version - we fallback to that if we detect the CPU doesn't support AVX2 or if the target array is less than 1500bp.

I didn't vectorize the query array transformation to keep things simple.

Performance results from running test_perf2.sh (just the SHW cases: all other cases are basically unaffected, because no time is spent in transformSequences):

perf-new.txt

perf-old.txt

Screenshot from 2026-07-07 00-10-21

I've added a simd_util.h function for any future SIMD work - I've got a couple ideas for HW & NW if this can get merged.

Appreciate this is a fairly large drive-by PR, happy to explain/change anything.

transformSequences is the bottleneck for SHW matches against large
targets. We spend all our time transforming the input sequences before
doing the matching.

This change vectorizes transformSequences with AVX2. It also introduces
some utility functions & patterns for handling SIMD runtime dispatching.
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