Skip to content

Speed up GRO file reading - #995

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

padix-key merged 1 commit into
biotite-dev:mainfrom
padix-key:perf/strucio-gro-read

Conversation

@padix-key

Copy link
Copy Markdown
Member

GROFile.get_structure() parsed each atom line in a Python loop and assigned every value individually into NumPy arrays (7 scalar __setitem__ calls per atom). In addition, _is_int() (used by get_structure() and get_model_count() to find model starts) raised and caught a ValueError for every atom line.

Fix:

  • Parse annotation and coordinate columns with list comprehensions and assign each column at once.
  • _is_int() returns False early for lines containing a ., which int() can never parse (all atom and box lines), avoiding exception handling.

Results are identical (values and dtypes checked against main).

Input Function before after speedup
1aki.gro (1k atoms) get_structure(model=1) 3.23 ms 1.18 ms 2.7x
1l2y.gro (38 models x 304 atoms) get_structure() 0.99 ms 0.41 ms 2.4x
1igy.gro get_structure(model=1) 37.5 ms 14.0 ms 2.7x
waterbox.gro get_structure(model=1) 11.4 ms 2.4 ms 4.7x
1aki.gro get_model_count() 0.67 ms 0.046 ms 14.6x

Note: for malformed multi-model files where a later model has a different atom count, a ValueError (broadcasting) is now raised instead of an IndexError/silently partially filled coordinates.

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

Authored by Claude

@codspeed

codspeed Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Merging this PR will regress 3 benchmarks

⚡ 14 improved benchmarks
❌ 3 regressed benchmarks
✅ 92 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_match_kmer_selection[BucketKmerTable(10000)-11*11*1*1***111] 648.6 µs 771.5 µs -15.93%
❌ benchmark_cell_list_compute_contacts[MAPPING] 22.9 ms 26.7 ms -14.32%
❌ 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 647.7 µs ×4.9
⚡ benchmark_hbond 29.7 ms 10.1 ms ×2.9
⚡ benchmark_similar_kmers 483 µs 201.8 µs ×2.4
⚡ benchmark_superimpose_multi_model[superimpose] 14.4 ms 6.4 ms ×2.3
⚡ benchmark_get_assembly 1,594.7 ms 836 ms +90.77%
⚡ benchmark_superimpose[superimpose_homologs] 60.6 ms 33.6 ms +80.49%
⚡ benchmark_superimpose_multi_model[superimpose_homologs] 74.2 ms 44.8 ms +65.69%
⚡ benchmark_score_threshold_rule[None] 3.3 s 2 s +65.28%
⚡ benchmark_score_threshold_rule[11*11*1*1***111] 3.3 s 2 s +65.11%
⚡ benchmark_superimpose[superimpose_without_outliers] 31.9 ms 20.8 ms +53.31%
⚡ benchmark_superimpose[superimpose_structural_homologs] 53.4 ms 44.8 ms +19.08%
⚡ benchmark_set_structure[bcif-True] 39 ms 32.8 ms +18.95%
⚡ benchmark_set_structure[bcif-False] 17.7 ms 15.1 ms +16.74%
🆕 benchmark_stack[10] N/A 6.7 ms N/A
🆕 benchmark_stack[2] N/A 2 ms N/A

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-gro-read (685fbd5) 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-gro-read branch from fb79bda to 685fbd5 Compare November 10, 2026 17:19
@padix-key
padix-key merged commit d46cc4e into biotite-dev:main Nov 10, 2026
32 of 33 checks passed

This branch was previously deployed

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