β‘οΈ Speed up function _init_subplot
by 11%
#124
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.
π 11% (0.11x) speedup for
_init_subplot
inplotly/_subplots.py
β±οΈ Runtime :
785 microseconds
β710 microseconds
(best of110
runs)π Explanation and details
Here are the concrete optimizations for your code, focusing on runtime hot spots and reducing memory allocations. The main changes target the following inefficiencies identified from your profiling.
.format()
calls for generating axis and subplot labels. These are replaced by much faster f-strings.All original logic and function signatures are preserved, as required.
Key optimizations:
.format()
replaced by f-strings for fast label generation._init_subplot
._validate_coerce_subplot_type
(was repeated in every usage).This version will be notably faster, especially for the most common code paths identified in your profiling.
β Correctness verification report:
π Generated Regression Tests Details
To edit these changes
git checkout codeflash/optimize-_init_subplot-mb2he6y4
and push.