⚡️ Speed up function plasma by 14%
#77
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.
📄 14% (0.14x) speedup for
plasmainsrc/bokeh/palettes.py⏱️ Runtime :
1.07 milliseconds→940 microseconds(best of102runs)📝 Explanation and details
The optimized code achieves a 14% speedup by eliminating repeated
math.floor()calls within the generator expression.Key optimization: Instead of calling
math.floor(i)for each floating-point index fromnp.linspace(), the code now:np.linspace()indices.astype(int)Why this is faster: The original code called
math.floor()for every element during tuple construction (98.6% of total time), creating significant per-element overhead. NumPy'sastype(int)performs the same floor operation but vectorized in C, eliminating the Python function call overhead.Performance benefits are most pronounced for larger palettes: Test results show the optimization provides the biggest gains when
nis large (e.g., 30%+ faster for n=256, 17-25% faster for n=100), while smaller palettes (n<10) see minimal or slightly slower performance due to the overhead of the additional NumPy operations. This makes the optimization particularly valuable for applications requiring large color palettes.✅ Correctness verification report:
⚙️ Existing Unit Tests and Runtime
unit/bokeh/test_palettes.py::test_cmap_generator_function🌀 Generated Regression Tests and Runtime
🔎 Concolic Coverage Tests and Runtime
codeflash_concolic_5f34sbte/tmpc6qpbz9p/test_concolic_coverage.py::test_plasmaTo edit these changes
git checkout codeflash/optimize-plasma-mhbhgynkand push.