Skip to content

Conversation

@segin
Copy link
Owner

@segin segin commented Feb 11, 2026

This PR optimizes the logarithmicScale function in src/core/utility/utility.cpp to improve the performance of the spectrum analyzer visualization.

πŸ’‘ What:

Replaced the iterative std::log10 loop in logarithmicScale with 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 logarithmicScale function 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:

  • f=1: ~4.5x faster
  • f=2: ~8.7x faster
  • f=4: ~17.5x faster

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

Optimized the `logarithmicScale` function in `src/core/utility/utility.cpp` by
introducing a precomputed Lookup Table (LUT) for the most common scale factors
(0 to 4).

The previous implementation relied on a loop that repeatedly called `std::log10`,
which was a significant bottleneck in the spectrum analyzer's rendering path.

Key changes:
- Defined a static LUT with 16,384 entries for scale factors 0-4.
- Implemented a thread-safe static initializer to populate the LUT on first use.
- Replaced the loop with a fast nearest-neighbor lookup for scale factors < 5.
- Provided a fallback loop for scale factors >= 5 to maintain full functionality.

Performance results (from standalone benchmark):
- f=1: ~21ns -> ~4.6ns (~4.5x faster)
- f=2: ~41ns -> ~4.7ns (~8.7x faster)
- f=4: ~100ns -> ~5.7ns (~17.5x faster)

Accuracy:
The 16,384 entry LUT ensures a maximum error of ~0.0048 for f=4, which
corresponds to less than 2 pixels of error on a typical 350-pixel high
spectrum display, making the optimization visually indistinguishable
from the original calculation.

Co-authored-by: segin <[email protected]>
@google-labs-jules
Copy link
Contributor

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@segin segin merged commit 0cfb2b1 into master Feb 11, 2026
0 of 2 checks passed
@segin segin deleted the optimize-log-scale-lut-11172138513976651972 branch February 11, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant