⚡️ Speed up function _use_gl by 61%
#69
Open
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.
📄 61% (0.61x) speedup for
_use_glinsrc/bokeh/embed/bundle.py⏱️ Runtime :
1.12 milliseconds→699 microseconds(best of49runs)📝 Explanation and details
The optimization achieves a 60% speedup by eliminating two key performance bottlenecks:
1. Generator Expression Overhead Removal
The original
_any()function usedany(query(x) for x in objs), which creates a generator object with associated overhead. The optimized version replaces this with a directforloop that short-circuits immediately when a match is found, avoiding generator creation and method call overhead.2. Function Call Chain Elimination
The original
_use_gl()made two function calls:_any()+ a lambda function for each object. The optimized version inlines this logic into a single loop, eliminating:_any()function call overheadPerformance Characteristics by Test Case:
The optimization maintains identical behavior while reducing computational overhead through direct iteration and eliminating unnecessary abstraction layers.
✅ Correctness verification report:
⚙️ Existing Unit Tests and Runtime
unit/bokeh/embed/test_bundle.py::Test__use_gl.test_with_glunit/bokeh/embed/test_bundle.py::Test__use_gl.test_without_gl🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-_use_gl-mhb721vband push.