Switch to wait-free FIFO instead of mutex + double-buffering for sidechain sample submission.
Bug #1179027 reported by
RJ Skerry-Ryan
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Mixxx |
Fix Released
|
Low
|
RJ Skerry-Ryan |
Bug Description
Writing to the sidechain locks mutexes. Also the double-buffering waits for a full buffer of 65536 samples to be processed before recording/shoutcast processes it. This adds about .75 seconds of latency to internet broadcasting.
Related branches
lp:~mixxxdevelopers/mixxx/fixes_sidechain_refactor
- Mixxx Development Team: Pending requested
- Diff: 0 lines
Changed in mixxx: | |
milestone: | none → 1.12.0 |
assignee: | nobody → RJ Ryan (rryan) |
importance: | Undecided → Low |
Changed in mixxx: | |
status: | In Progress → Fix Committed |
Changed in mixxx: | |
status: | Fix Committed → Fix Released |
To post a comment you must log in.
I've experimented with this and subjectively it's an improvement. At 1ms latency on my macbook, recording causes xruns using lp:mixxx but with this FIFO change there are none.
The timing change is a little confusing to interpret:
lp:mixxx
Debug [Main]: Stat("EngineSid eChain: submitSamples" ,"count= 56730,sum= 2.0621e+ 07ns,average= 363.493ns, min=103ns, max=31814ns, variance= 428647ns^ 2,stddev= 654.712ns" )
lp:mixxx with sidechain FIFO:
Debug [Main]: Stat("EngineSid eChain: writeSamples" ,"count= 55378,sum= 4.1629e+ 08ns,average= 7517.24ns, min=335ns, max=149221ns, variance= 1.2783e+ 07ns^2, stddev= 3575.33ns" )
Not using a mutex is enough of a reason to make this change even if this code is a 25x slow-down. But why is it slower?
This change actually signals the sidechain thread to wake on every write. The slowdown is actually due to the signaling. The FIFO write should be about the same as the original code since it's mostly a memcpy.
To prove this, I changed the code to only signal the sidechain thread once the FIFO was 4/5ths full:
Debug [Main]: Stat("EngineSid eChain: writeSamples" ,"count= 60029,sum= 2.42839e+ 07ns,average= 404.536ns, min=171ns, max=25886ns, variance= 345917ns^ 2,stddev= 588.147ns" )
So this is approximately performance neutral if we keep the old behavior of submitting once we have ~65536 samples.
Now the question for me is how often should we wake the sidechain? The sooner we wake it the lower latency shoutcast will have.