Skip to content

Comments

Performance: Optimize Mel filterbank application with sparse matrix indices#9

Open
ysdede wants to merge 1 commit intomainfrom
bolt-perf-sparse-filterbank-10792195913597466588
Open

Performance: Optimize Mel filterbank application with sparse matrix indices#9
ysdede wants to merge 1 commit intomainfrom
bolt-perf-sparse-filterbank-10792195913597466588

Conversation

@ysdede
Copy link
Owner

@ysdede ysdede commented Feb 18, 2026

Performance Improvement

Optimized the Mel filterbank matrix multiplication step in computeRawMel by leveraging the sparsity of the filterbank matrix.

Changes:

  1. Precomputation: In MelSpectrogram constructor, we now scan the melFilterbank matrix (which is ~98.5% sparse) and store the start and end indices of non-zero values for each mel bin in _fbStart and _fbEnd (Int32Arrays).
  2. Execution: In the inner loop of computeRawMel, we now iterate only from start to end instead of the full nFreqBins range.

Impact:

  • Speedup: ~3.5x faster process() calls.
  • Benchmark (30s audio):
    • Baseline: ~418ms/call
    • Optimized: ~118ms/call
  • Correctness: Verified with npm test, passing all 52 tests including numerical cross-validation against ONNX reference implementation.

Verification:
Run npm test to verify correctness.
(Optional) Create a benchmark script (like the one used during development) to verify speedup.


PR created automatically by Jules for task 10792195913597466588 started by @ysdede

…ndices

- Precompute `_fbStart` and `_fbEnd` indices in `MelSpectrogram` constructor to identify non-zero ranges in the filterbank.
- Update `computeRawMel` to iterate only over non-zero elements, skipping unnecessary multiplications by zero.
- Yields a ~3.5x speedup (RTF from 0.014 to 0.004) in benchmarks.
- Verified with existing tests and ONNX reference cross-validation.
Repository owner deleted a comment from google-labs-jules bot Feb 20, 2026
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