Skip to content

Speed up MOL/SDF structure writing - #1020

Merged
padix-key merged 1 commit into
biotite-dev:mainfrom
padix-key:perf/strucio-mol-ctab
Nov 10, 2026
Merged

padix-key merged 1 commit into
biotite-dev:mainfrom
padix-key:perf/strucio-mol-ctab

Conversation

@padix-key

Copy link
Copy Markdown
Member

write_structure_to_ctab() (used by MOLFile.set_structure(), SDRecord.set_structure() and mol.set_structure()) built each atom/bond line by indexing NumPy arrays element-wise (atoms.coord[i, 0], atoms.element[i], charge[i], bond array rows), and re-formatted constant padding fields for every line.

Fix: iterate over tolist() versions of coordinates, elements, charges and the bond array, and format the constant unused fields once. Output is identical to main (V2000 and V3000).

Input Call before after speedup
13136.sdf (39 atoms) write_structure_to_ctab(..., "V2000") 0.187 ms 0.081 ms 2.3x
HWB.sdf write_structure_to_ctab(..., "V2000") 0.169 ms 0.072 ms 2.3x
ATP (CCD) SDRecord.set_structure(..., version="V2000") 0.235 ms 0.093 ms 2.5x
ATP (CCD) SDRecord.set_structure(..., version="V3000") 0.186 ms 0.077 ms 2.4x
13136.sdf SDRecord.set_structure(..., version="V2000") 0.190 ms 0.084 ms 2.3x

Tests run: tests/structure/io/test_mol.py.

Authored by Claude

@codspeed

codspeed Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Merging this PR will regress 4 benchmarks

⚡ 16 improved benchmarks
❌ 4 regressed benchmarks
✅ 89 untouched benchmarks
🆕 2 new benchmarks
⏩ 14 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ benchmark_cell_list_compute_contacts[MAPPING] 22.9 ms 27.1 ms -15.6%
❌ benchmark_match_kmer_selection[BucketKmerTable(10000)-None] 652.9 µs 771.1 µs -15.33%
❌ benchmark_match[BucketKmerTable(10000)-11*11*1*1***111] 837.3 µs 957.5 µs -12.55%
❌ benchmark_cell_list_compute_contacts[PAIRS] 22.7 ms 25.8 ms -12.11%
⚡ benchmark_find_rotatable_bonds 177.1 ms 26.7 ms ×6.6
⚡ benchmark_superimpose[superimpose] 3,198.9 µs 645 µs ×5
⚡ benchmark_hbond 29.7 ms 10.1 ms ×2.9
⚡ benchmark_similar_kmers 483 µs 199.9 µs ×2.4
⚡ benchmark_superimpose_multi_model[superimpose] 14.4 ms 6.4 ms ×2.3
⚡ benchmark_get_assembly 1,594.7 ms 836.2 ms +90.71%
⚡ benchmark_superimpose[superimpose_homologs] 60.6 ms 33.6 ms +80.28%
⚡ benchmark_score_threshold_rule[11*11*1*1***111] 3.3 s 1.9 s +70.72%
⚡ benchmark_score_threshold_rule[None] 3.3 s 1.9 s +70.71%
⚡ benchmark_superimpose_multi_model[superimpose_homologs] 74.2 ms 44.8 ms +65.74%
⚡ benchmark_superimpose[superimpose_without_outliers] 31.9 ms 20.8 ms +52.95%
⚡ benchmark_match_kmer_selection[KmerTable-None] 642.6 µs 526.3 µs +22.1%
⚡ benchmark_superimpose[superimpose_structural_homologs] 53.4 ms 44.8 ms +19.18%
⚡ benchmark_set_structure[bcif-True] 39 ms 32.8 ms +19.03%
⚡ benchmark_match[KmerTable-None] 739.6 µs 623.8 µs +18.56%
⚡ benchmark_set_structure[bcif-False] 17.7 ms 15.1 ms +17.01%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing padix-key:perf/strucio-mol-ctab (0cfd4d1) with main (81df912)2

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

  2. No successful run was found on main (b0d32ca) during the generation of this report, so 81df912 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@padix-key
padix-key force-pushed the perf/strucio-mol-ctab branch from 749e33d to 0cfd4d1 Compare November 10, 2026 17:19
@padix-key
padix-key merged commit 5eaa9e3 into biotite-dev:main Nov 10, 2026
32 of 33 checks passed

This branch was previously deployed

1 inactive deployment
publish — 0cfd4d1b Deployed Nov 10, 2026 by padix-key via Upload package to GitHub Releases & PyPI #1559
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