ws-cleanup: Pcm.collect reads a known length in one call into the result (no copy); README links the guide

Measured in an A/B of the touched paths (best of 3-4, one core): LuaJIT wav decode through Pcm.drain was ~10%
slower than the old single read; now within noise.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
4DBugandClaude Opus 5.5 committed 2026-10-31 13:19:43 -05:00
1 parent c4f6e2ca1c
commit 790060d804
2 files changed
+12 -1

No files matched your search

+10
View File
@@ -117,6 +117,16 @@ function Pcm.collect(src: Source, maxFrames: number?): (Types.Audio?, Err.Err?)
local total = 0
local limit = maxFrames or 2 ^ 31
local tmp: buffer? = nil
-- a known length: one read straight into the result (decoders write into a big enough out buffer: no copy)
if src.frames > 0 and src.frames <= limit then
local b, n = src:read(src.frames, data)
if n > 0 then
if b ~= data then
buffer.copy(data, 0, b, 0, math.min(n, cap) * ch * 4)
end
total = math.min(n, cap)
end
end
while true do
local b, n = src:read(16384, tmp)
if n <= 0 then