Don't call np.identity() in transforms. #10327
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.
EDIT: see below.
Speeds up setting up of subplots by ~3% and their drawing by ~2% at a
reasonably limited cost in legibility.
The difference is actually not easy to observe because variation in
timings are much greater than 3% from run to run.
In a call like
subplots(10, 10)
, just setting up the figure callsnp.identity(3)
1801 times and actually drawing the figure another 1705times (measured by manually instrumenting the calls to identity() in the
old version. At the same time,
and
show that on my machine, a call to np.identity(3) is approximately 16us
slower than copying a preexisting matrix; multiplying this by 1801 shows
that the calls to identity correspond to an excess time of ~27ms.
Finally, setting up the axes and drawing it can be timed using
which shows that (on my machine) setting up the subplots takes ~850ms
and drawing them ~1300ms (but again, with a lot of jitter).
Hence, the gain from the patch should be ~3% for the setup and ~2% for
the draw.
Edit: I realized that my timings were invalid because I had https://pypi.org/project/ipython-autoimport/ active which, while reasonably fast, still messed up the timings a bit.
The real gain is probably ~5x less than what advertised above, so ~0.5%. Feel free to close if you think this is not worth it.
PR Summary
PR Checklist