Skip to content

Comments

Performance: Sparse Mel Filterbank Application#10

Open
ysdede wants to merge 1 commit intomainfrom
perf/sparse-mel-filterbank-6584113485522433090
Open

Performance: Sparse Mel Filterbank Application#10
ysdede wants to merge 1 commit intomainfrom
perf/sparse-mel-filterbank-6584113485522433090

Conversation

@ysdede
Copy link
Owner

@ysdede ysdede commented Feb 19, 2026

What changed

Modified MelSpectrogram to precompute start and end indices of non-zero filterbank values.
Updated computeRawMel to iterate only over these relevant indices instead of the full dense matrix.

Why it was needed

The Mel filterbank matrix is extremely sparse (approx 98% zeros). The previous implementation performed a dense matrix-vector multiplication for every frame, wasting cycles on zero-value multiplications. Profiling identified this inner loop as a major bottleneck.

Impact

  • 3.75x speedup in raw mel computation (measured: 71ms -> 18.9ms for 5s audio processing).
  • Significant reduction in CPU usage for real-time applications.

How to verify

  1. Run npm test to ensure all tests pass (including numerical correctness checks against ONNX reference).
  2. Create a benchmark script:
    import { MelSpectrogram } from './src/mel.js';
    const mel = new MelSpectrogram({ nMels: 128 });
    const audio = new Float32Array(16000 * 5); // 5s dummy audio
    const start = performance.now();
    for(let i=0; i<100; i++) mel.process(audio);
    console.log((performance.now() - start)/100);
  3. Observe measurable performance improvement compared to baseline.

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

- Precompute start/end indices for non-zero filterbank values in constructor
- Iterate only over relevant indices in `computeRawMel` loop
- ~3.75x speedup in raw mel computation (71ms -> 19ms)
- Verified with existing tests and custom benchmark
@kiloconnect
Copy link

kiloconnect bot commented Feb 19, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • .jules/bolt.md - Documentation file (learning note)
  • src/mel.js - Performance optimization for sparse mel filterbank

Summary

This PR implements a performance optimization for sparse mel filterbanks:

  1. .jules/bolt.md - Documentation noting that the mel filterbank matrix is ~98% sparse and iterating over the full matrix in the a 3. hot loop was75x bottleneck

  2. src/mel.js - Optimized the inner mel filterbank loop:

    • Precomputes sparse filterbank indices (_fbStart, _fbEnd) in the constructor
    • Modified the inner loop to only iterate over non-zero entries, reducing unnecessary multiplications

The implementation is correct:

  • Sparse indices are properly computed for each mel bin
  • Edge cases are handled (completely zero mel bins result in no iterations, which is fine since logZeroGuard prevents log(0))
  • The optimization follows existing code patterns

No issues found.

Repository owner deleted a comment from google-labs-jules bot Feb 20, 2026
Repository owner deleted a comment from chatgpt-codex-connector 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