Skip to content

Perf: stream LoudnessMeter blocks through a ring buffer (−127 MB analysis spike) - #116

Merged
sanylax0 merged 1 commit into
mainfrom
claude/repo-review-improvements-yvk3t7-loudness-memory
Jul 20, 2026
Merged

sanylax0 merged 1 commit into
mainfrom
claude/repo-review-improvements-yvk3t7-loudness-memory

Conversation

@sanylax2

Copy link
Copy Markdown
Collaborator

Part 1 of the CPU/memory audit (full findings summarized in the audit report; this PR is the largest single memory win).

What

LoudnessMeter.integratedLUFS allocated a full-length [Double] weighted buffer — ~127 MB for a 6-minute track — on top of the ~63 MB mono analysis buffer. That transient spike runs while music plays (post-ready analysis) and feeds directly into the jetsam budget.

The K-weighted samples now stream through a single block-sized ring buffer (~140 KB). Each 400 ms block's mean-square is summed from the ring in the same logical order as the old whole-buffer loop, so the output is bit-identical — same filters, same summation order, same gating.

Verification

New testStreamingMatchesReferenceImplementation embeds the pre-optimization implementation verbatim and asserts exact equality across 44.1 kHz, 48 kHz, and 44 056 Hz (a rate where integer truncation makes the block a non-multiple of the hop — the tail case). Runs in core-tests-linux.

No functional or visual change; analysis peak memory drops by ~127 MB per track.

🤖 Generated with Claude Code

https://claude.ai/code/session_013TJoWkqg8bzkGdzxWhWjWP


Generated by Claude Code

…ysis spike)

integratedLUFS allocated a full-length [Double] weighted buffer (~127 MB
for a 6-minute track) on top of the mono analysis buffer — a transient
spike that ran while music plays and fed the jetsam budget. The weighted
samples now stream through a single block-sized ring (~140 KB); each
400 ms block's mean-square is summed from the ring in the same order as
before, so results are bit-identical (regression test compares against
the old implementation verbatim, including at sample rates where the
block isn't a whole multiple of the hop).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013TJoWkqg8bzkGdzxWhWjWP
@sanylax0
sanylax0 merged commit f7fbbce into main Jul 20, 2026
4 checks passed
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.

3 participants