Avoid expensive deepcopy when rotating Miller #533
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the change
Rotating a Miller instance with a Rotation calls
Miller.__getitem__
to handle improper rotations, regardless of whether any rotations are actually improper.As
Miller.__getitem__
involves a deepcopy, avoiding this when not necessary provides a significant speedup, depending on the complexity of the associated Phase.Progress of the PR
Minimal example of the bug fix or new feature
Current
505 μs ± 18.6 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
1.7 ms ± 48.2 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
New change
346 μs ± 41.4 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
350 μs ± 16.9 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
Of course, with improper rotations, the runtime is the same:
506 μs ± 26.3 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
1.69 ms ± 44.3 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
For reviewers
__init__.py
.section in
CHANGELOG.rst
.__credits__
inorix/__init__.py
and in.zenodo.json
.