Skip to content

Comments

feat(mel): optimize incremental mel processing#24

Closed
ysdede wants to merge 1 commit intomasterfrom
incremental-mel-optimization-2619755791687996283
Closed

feat(mel): optimize incremental mel processing#24
ysdede wants to merge 1 commit intomasterfrom
incremental-mel-optimization-2619755791687996283

Conversation

@ysdede
Copy link
Owner

@ysdede ysdede commented Feb 7, 2026

This PR addresses the inefficient incremental mel processing in src/mel.js.

Changes:

  • JsPreprocessor.computeRawMel(audio, startFrame=0): Added startFrame parameter. The STFT loop now starts from startFrame. The output rawMel array is initialized with zeros, so frames before startFrame are zeroed.
  • IncrementalMelProcessor.process (Incremental Path): Calculates safeFrames (cached prefix length) and passes it to computeRawMel. This skips STFT computation for the prefix. The prefix is then filled from this._cachedRawMel.
  • IncrementalMelProcessor.process (Full Path): Refactored to call computeRawMel once, then normalizeFeatures. Previously it called this.preprocessor.process(audio) (full computation + norm) AND this.preprocessor.computeRawMel(audio) (full computation), doing double work.

Verification:

  • Validated with npm test (tests/mel.test.mjs). All tests passed.
  • Performance benchmark (reproduction script) showed:
    • Full processing (cache miss): ~102ms -> ~59ms (~1.7x speedup).
    • Incremental processing (70% overlap): ~65ms -> ~28ms (~2.3x speedup).

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

Refactors `JsPreprocessor.computeRawMel` to accept an optional `startFrame` parameter, allowing STFT computation to be skipped for cached prefixes.
Updates `IncrementalMelProcessor.process` to utilize this optimization, avoiding recomputation of `safeFrames` and instead filling them from the cache.
Also optimizes the "cache miss" path in `IncrementalMelProcessor.process` to avoid double computation (previously calling both `process` and `computeRawMel`).

Results in ~2x speedup for full processing (cache miss) and significantly faster incremental updates (skipping proportional to overlap).

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Copy link
Owner Author

@ysdede ysdede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary: This overlaps with #29 (startFrame support and full-path refactor) and includes the same changes.
Recommendation: Close as superseded by #29 to avoid conflicts (also package-lock churn).
Tests: npm test

@ysdede
Copy link
Owner Author

ysdede commented Feb 9, 2026

Handled in PR#34 (release branch). Closing superseded PR.

@ysdede ysdede closed this Feb 9, 2026
@ysdede ysdede deleted the incremental-mel-optimization-2619755791687996283 branch February 9, 2026 21:08
@google-labs-jules
Copy link
Contributor

Handled in PR#34 (release branch). Closing superseded PR.

Understood. Acknowledging that this work is now obsolete and stopping work on this task.

Repository owner deleted a comment from google-labs-jules bot Feb 17, 2026
Repository owner deleted a comment from coderabbitai bot Feb 17, 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