Bolt: Optimized Mel Filterbank Matrix Multiplication#4
Conversation
Precomputes the start and end indices of non-zero values in the Mel filterbank matrix to avoid multiplying by zero. This reduces the complexity of the inner loop from O(nFreqBins) to O(filterWidth), resulting in a ~3.6x speedup (834ms -> 232ms for 60s audio). Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
📝 WalkthroughWalkthroughAdds documentation and implements a sparsity optimization for Mel filterbank computation. The optimization precomputes the non-zero range boundaries for each Mel filter during initialization, then constrains the inner loop during computation to skip zero coefficients, achieving approximately 3.6x performance improvement for audio processing. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What:
Precomputed the start and end indices (
_fbStart,_fbEnd) for each row in the Mel filterbank matrix in theMelSpectrogramconstructor. UpdatedcomputeRawMelto use these bounds in the inner loop instead of iterating over all frequency bins.Why:
The Mel filterbank is a sparse, triangular matrix. Iterating over all 257 frequency bins (for 512 FFT) for every Mel bin involves many multiplications by zero. By skipping these zeros, we significantly reduce the number of floating-point operations.
Impact:
Measurement:
Ran
bench.js(created temporarily) which processes 60s of random noise 10 times. Verified correctness with existing tests, including ONNX numerical cross-validation.PR created automatically by Jules for task 16003308894749395639 started by @ysdede
Summary by CodeRabbit
Documentation
Added documentation on Mel filterbank sparsity optimization strategies and performance improvements in audio processing.
Refactor
Optimized Mel spectrogram computation by leveraging sparsity patterns in filterbank matrices, achieving approximately 3.6x performance improvement for audio processing without API changes.