You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2bf8895
Browse filesBrowse the repository at this point in the historyBrowse files
fix: bound the streaming mel buffer to a sliding window (fixesmudler#63, the streaming RSS leak) (mudler#69)
Root cause: parakeet_capi_stream_feed's streaming session keeps every mel frame from
stream_begin onward in mel_buf and rebuilds that whole, ever-growing array on every feed call,
even though the decoder (feed_available's window()) never reads a frame older than
mel_buffer_idx - pre_encode_cache_size() frames back — so those old frames are provably dead
the moment the decoder consumes past them. Because each rebuild requests a uniquely, ever-larger
allocation for the life of the stream, the allocator can never reuse an earlier call's freed
(now permanently too-small) block, so process RSS grows with the cumulative history of buffer
sizes rather than the small, bounded set of frames actually still needed — which is why neither
stream_free nor a fresh stream_begin reclaims it.
The fix: track the absolute frame index of mel_buf's first column (mel_buf_origin) and, on
every append, drop the prefix strictly before mel_buffer_idx - pre_encode_cache_size() — the
exact bound window() already relies on — so mel_buf stays bounded to
O(pre_encode_cache_size + chunk_size) instead of O(stream length). No API change, no behavioural
change: window()'s absolute-index reads are translated into mel_buf's origin-relative local
columns, and the surviving frames are carried forward byte-for-byte.
Measurement (CPU + Accelerate build, realtime_eou_120m-v1 q8, 120 s of silence fed in 20 ms
chunks, RSS sampled at 30/60/90/120 s of audio fed): growth over the last 60 s drops from
178 MB to 0.5 MB; the same run's wall time drops from ~14 minutes to ~13 seconds, since the
unbounded rebuild was O(T) per call, O(T²) total. A LibriSpeech utterance's transcript is
byte-identical before and after.
0 commit comments