-
Notifications
You must be signed in to change notification settings - Fork 0
⚡️ Speed up function _pop_renderer_args by 172%
#65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: branch-3.9
Are you sure you want to change the base?
⚡️ Speed up function _pop_renderer_args by 172%
#65
Conversation
The optimization replaces the original's `kwargs.pop('source', ColumnDataSource())` pattern with an explicit conditional check. In the original code, `pop()` with a default argument **always** constructs the `ColumnDataSource()` object, even when 'source' exists in kwargs. The optimized version only creates the expensive `ColumnDataSource()` object when 'source' is actually missing.
From the line profiler, the original code spent 99.4% of its time (25.2ms) on the `kwargs.pop('source', ColumnDataSource())` line, while the optimized version only spends 98.2% on `ColumnDataSource()` creation but with significantly less total time (8.8ms) because it's only called when needed.
The test results show this optimization is most effective when:
- **'source' is present in kwargs** (10,000-20,000% speedup in many tests)
- **Large datasets or complex scenarios** where avoiding unnecessary object creation matters most
- **Cases without 'source'** see minimal improvement since `ColumnDataSource()` still gets called
The 172% speedup comes from eliminating wasteful object construction - a common Python performance anti-pattern where default arguments in `pop()` are eagerly evaluated regardless of necessity.
src/bokeh/plotting/_renderer.py
Outdated
| from bokeh.models import ColumnDataSource | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| from bokeh.models import ColumnDataSource |
src/bokeh/plotting/_renderer.py
Outdated
| from bokeh.models import ColumnDataSource | ||
|
|
||
| import logging # isort:skip | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/bokeh/plotting/_renderer.py
Outdated
| from bokeh.models import ColumnDataSource | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| from bokeh.models import ColumnDataSource |
src/bokeh/plotting/_renderer.py
Outdated
| from bokeh.models import ColumnDataSource | ||
|
|
||
| import logging # isort:skip | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📄 172% (1.72x) speedup for
_pop_renderer_argsinsrc/bokeh/plotting/_renderer.py⏱️ Runtime :
9.04 milliseconds→3.32 milliseconds(best of307runs)📝 Explanation and details
The optimization replaces the original's
kwargs.pop('source', ColumnDataSource())pattern with an explicit conditional check. In the original code,pop()with a default argument always constructs theColumnDataSource()object, even when 'source' exists in kwargs. The optimized version only creates the expensiveColumnDataSource()object when 'source' is actually missing.From the line profiler, the original code spent 99.4% of its time (25.2ms) on the
kwargs.pop('source', ColumnDataSource())line, while the optimized version only spends 98.2% onColumnDataSource()creation but with significantly less total time (8.8ms) because it's only called when needed.The test results show this optimization is most effective when:
ColumnDataSource()still gets calledThe 172% speedup comes from eliminating wasteful object construction - a common Python performance anti-pattern where default arguments in
pop()are eagerly evaluated regardless of necessity.✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
🔎 Concolic Coverage Tests and Runtime
codeflash_concolic_cthbg6_3/tmpnk7ine9m/test_concolic_coverage.py::test__pop_renderer_argsTo edit these changes
git checkout codeflash/optimize-_pop_renderer_args-mhb5w7c6and push.