Skip to content

Speed 2 - Needs Speed 1 - #467

Closed
nabobalis wants to merge 2 commits into
wtbarnes:mainfrom
nabobalis:speed_2
Closed

nabobalis wants to merge 2 commits into
wtbarnes:mainfrom
nabobalis:speed_2

Conversation

@nabobalis

Copy link
Copy Markdown
Collaborator

No description provided.

Avoid repeated expensive recomputation in the level populations
calculation while keeping the output bit-identical:

- Cache the Ion instances returned by next_ion()/previous_ion() for
  internal use so that rate matrices of the recombining ion are only
  computed once rather than on every density iteration.
- Cache the density-independent sum of the two-ion rate matrices.
- Memoize plasmapy atomic_number/atomic_symbol/element_name lookups,
  which construct an expensive Particle object on every call.
- Share the proton-electron ratio with the next ion since it only
  depends on temperature and the abundance/ionization datasets.

Benchmark (21 temperatures x 9 densities): Fe XXIII 73.5->7.2 s,
Ca XVIII 74.3->8.1 s, O VI 73.3->9.3 s, Fe XII (single-ion model)
9.9->5.0 s, coupled n-T 14.5->3.0 s.
Further speed up of the level populations calculation (and anything
else that creates many Ion instances or reads many datasets), again
keeping the output bit-identical:

- DataIndexerHDF5.__getitem__ now does the membership check, child
  indexer creation, and read with a single open of the HDF5 file
  instead of two to three opens per access.
- Memoize the set of available ion names and the database fiasco
  version per database file, keyed on the file modification time and
  size so that rebuilding the database invalidates the cache. This
  avoids re-reading the full ion index on every Ion instantiation.

Ion instantiation drops from ~3.7 ms to ~1.9 ms and
fiasco.proton_electron_ratio from ~2.1 s to ~1.5 s. O VI level
populations (21 T x 9 n): 9.3 -> 8.1 s, dominated by np.linalg.solve.
@nabobalis nabobalis closed this Aug 10, 2026
@nabobalis
nabobalis deleted the speed_2 branch August 10, 2026 23:59
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