Skip to content

Perf: align_multiple speedup from using typed memoryviews - #927

Merged
padix-key merged 1 commit into
biotite-dev:mainfrom
jberg5:align-multiple-memoryview
Jul 18, 2026
Merged

Perf: align_multiple speedup from using typed memoryviews#927
padix-key merged 1 commit into
biotite-dev:mainfrom
jberg5:align-multiple-memoryview

Conversation

@jberg5

@jberg5 jberg5 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Very small change, decent performance impact depending on problem dimensions. Typed memoryviews already existed for code_count; we just weren't using them. Switching lets the indexing run at C speed.

Let's say the length of the alphabet is A, and the number of sequences is N, and the sequence length is L: this indexing was running O(N^2 * A^2) times. So for small L but large A and N the speedup is quite significant. For large L (e.g. cas9, which is what the benchmark uses here

fasta_file = fasta.FastaFile.read(data_dir("sequence") / "cas9.fasta")
), other steps of align_multiple dominate, so the wallclock improvement isn't so great.

I had claude run through a number of realistic-looking examples on a c4-standard-8 gcloud vm, this is what it came up with, should give you a sense of how things scale:

┌───────────────┬─────┬──────┬──────────┬─────────┬─────────┐
│    dataset    │  n  │ Lmed │  before  │  after  │ speedup │
├───────────────┼─────┼──────┼──────────┼─────────┼─────────┤
│ kunitz (BPTI) │ 99  │ 53   │ 3087 ms  │ 195 ms  │ 15.9×   │
├───────────────┼─────┼──────┼──────────┼─────────┼─────────┤
│ ig_iset       │ 45  │ 90   │ 690 ms   │ 100 ms  │ 6.9×    │
├───────────────┼─────┼──────┼──────────┼─────────┼─────────┤
│ globin_seed   │ 73  │ 114  │ 1979 ms  │ 398 ms  │ 5.0×    │
├───────────────┼─────┼──────┼──────────┼─────────┼─────────┤
│ pkinase       │ 37  │ 263  │ 915 ms   │ 512 ms  │ 1.8×    │
├───────────────┼─────┼──────┼──────────┼─────────┼─────────┤
│ aldh          │ 84  │ 462  │ 9421 ms  │ 7301 ms │ 1.3×    │
├───────────────┼─────┼──────┼──────────┼─────────┼─────────┤
│ cas9          │ 10  │ 1227 │ 805 ms   │ 770 ms  │ 1.05×   │
├───────────────┼─────┼──────┼──────────┼─────────┼─────────┤
│ globin N=25   │ 25  │ 146  │ 246 ms   │ 69 ms   │ 3.6×    │
├───────────────┼─────┼──────┼──────────┼─────────┼─────────┤
│ globin N=50   │ 50  │ 146  │ 1002 ms  │ 271 ms  │ 3.7×    │
├───────────────┼─────┼──────┼──────────┼─────────┼─────────┤
│ globin N=100  │ 100 │ 146  │ 3999 ms  │ 1071 ms │ 3.7×    │
├───────────────┼─────┼──────┼──────────┼─────────┼─────────┤
│ globin N=200  │ 200 │ 146  │ 16092 ms │ 4209 ms │ 3.8×    │
└───────────────┴─────┴──────┴──────────┴─────────┴─────────┘

So as for "how much faster," the answer is "it depends," but I think in any case this is the right change to make (and if I had to guess is what was intended from the beginning).

@padix-key

Copy link
Copy Markdown
Member

Your are completely right, thanks for the fix!

@codspeed-hq

codspeed-hq Bot commented Jul 16, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 10.31%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 102 untouched benchmarks
⏩ 14 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
benchmark_match_kmer_selection[BucketKmerTable(10000)-None] 353.3 µs 320.3 µs +10.31%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing jberg5:align-multiple-memoryview (1693bab) with main (1fa1b70)

Open in CodSpeed

Footnotes

  1. 14 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@jberg5

jberg5 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Test failure is unrelated, #929 should (hopefully) fix it tho!

@padix-key
padix-key merged commit 3b62826 into biotite-dev:main Jul 18, 2026
23 of 24 checks passed
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