β‘ Optimize logarithmicScale with LUT #31
Merged
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.
This PR optimizes the
logarithmicScalefunction insrc/core/utility/utility.cppto improve the performance of the spectrum analyzer visualization.π‘ What:
Replaced the iterative
std::log10loop inlogarithmicScalewith a precomputed Lookup Table (LUT) for scale factors 0 through 4. A LUT size of 16,384 entries was chosen to balance memory usage (approx. 320 KB total) and precision.π― Why:
The
logarithmicScalefunction is a "hot" function called hundreds of times per frame (e.g., once for each frequency bin in the spectrum analyzer). The original implementation's use of repeated transcendental function calls was inefficient.π Measured Improvement:
Benchmarking showed significant speedups across all common scale factors:
Precision remains very high, with a maximum error of approximately 0.0048 for the most aggressive scaling (f=4), which is well within the acceptable range for UI visualizations.
Existing functionality is preserved for all inputs, with a safe fallback loop for scale factors >= 5.
PR created automatically by Jules for task 11172138513976651972 started by @segin