β‘οΈ Speed up function _configure_shared_axes
by 10%
#120
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.
π 10% (0.10x) speedup for
_configure_shared_axes
inplotly/_subplots.py
β±οΈ Runtime :
374 microseconds
β340 microseconds
(best of174
runs)π Explanation and details
Here's a highly optimized version of your
_configure_shared_axes
function, preserving its signature and behavior, but significantly reducing overhead in its inner loops and redundant attribute lookups. The profiling shows that most of the time is spent in looping and attribute access, so this version uses local caching, loop restructuring, and short-circuiting to minimize those costs. All original comments are preserved except where code is changed.Major optimizations explained:
update_axis_matches
as a local function and removed unnecessary repeated checks.This version focuses on inner loop speed, local variable usage and tightest loop unrolling consistent with preserving structure and signature. For further gains, complete refactoring of data structures may be needed, which would change APIs.
β Correctness verification report:
π Generated Regression Tests Details
To edit these changes
git checkout codeflash/optimize-_configure_shared_axes-mb2gpisc
and push.