Skip to content

integrate: optimize save_all#449

Merged
adrn merged 3 commits intomainfrom
save-all-opt
Oct 13, 2025
Merged

integrate: optimize save_all#449
adrn merged 3 commits intomainfrom
save-all-opt

Conversation

@lgarrison
Copy link
Collaborator

@lgarrison lgarrison commented Aug 25, 2025

Describe your changes

This is a relatively small change to optimize orbit integrations with save_all=True. In general, turning on this option has resulting in puzzlingly slow integrations. Part of the bottleneck turns out to be making copies of the pos/vel arrays when wrapping them in Quantity objects during the output stage. This PR adds a copy kwarg to PhaseSpacePosition, Orbit, and MockStream to allow arrays to be passed though without copies.

The performance improvement is about 1.3x-2.5x, modest but worthwhile:

image

Note that the absolute performance is still lower than in #447 (save_all=False), but we do expect there to be some overhead to saving relatively large orbit arrays.

Although the focus of this PR is on the orbit integration performance, I did a general pass through the code to add copy=False when it was clearly safe to do so.

Checklist

  • Did you add tests?
  • Did you add documentation for your changes? (Docstrings)
  • Did you reference any relevant issues?
  • Did you add a changelog entry? (see CHANGES.rst)
  • Are the CI tests passing?
  • Is the milestone set?

@lgarrison lgarrison marked this pull request as draft August 25, 2025 19:14
@lgarrison lgarrison force-pushed the vectorize-more branch 2 times, most recently from a294345 to 4e64d07 Compare September 12, 2025 19:25
@lgarrison lgarrison force-pushed the vectorize-more branch 2 times, most recently from 22c4368 to 5bb1f06 Compare October 2, 2025 18:12
Base automatically changed from vectorize-more to main October 6, 2025 15:11
…kStream`

Allows the user to pass `copy=False` to improve performance when a copy
is not needed. The default is `copy=True`, preserving the original
behavior.
Also apply to Orbit and MockStream (PhaseSpacePosition subclasses). Note that
multiplying by a unit creates a copy of the value, so we can return such Quantities
without an additional copy.
@lgarrison lgarrison marked this pull request as ready for review October 7, 2025 14:42
@lgarrison lgarrison requested a review from adrn October 7, 2025 15:18
@adrn adrn added this to the v1.11 milestone Oct 13, 2025
Copy link
Owner

@adrn adrn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, and agree that this is worthwile!

@adrn adrn merged commit e946ad1 into main Oct 13, 2025
26 checks passed
@adrn adrn deleted the save-all-opt branch October 13, 2025 17:50
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