⚡️ Speed up function _ext_use_tables by 1,539%
#70
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.
📄 1,539% (15.39x) speedup for
_ext_use_tablesinsrc/bokeh/embed/bundle.py⏱️ Runtime :
57.8 milliseconds→3.53 milliseconds(best of215runs)📝 Explanation and details
The optimization reduces algorithmic complexity by eliminating redundant work in the nested loop structure.
Key changes:
if name == "bokeh" or name in names:reduces duplicate name lookupsPerformance impact:
The original code performed ~955,000
model.__module__.startswith(name)checks across all models for each extension name. The optimized version groups models upfront, reducing this to only checking models that actually belong to each extension's module prefix.Test case benefits:
HasProps.model_class_reverse_mapcontains many models, as it avoids the expensive nested iteration that dominated the original runtime profile (98.7% of execution time)✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
🔎 Concolic Coverage Tests and Runtime
codeflash_concolic_cthbg6_3/tmph2982e0k/test_concolic_coverage.py::test__ext_use_tablesTo edit these changes
git checkout codeflash/optimize-_ext_use_tables-mhb7a7hiand push.