Replace per-pair gain/pan mutex locking with snapshot - #3948
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: QUIET Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthrough
ChangesChannel gain and panning retrieval
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Refactor Suggested reviewers: Merge Risk: ⚪ Minimal · up to The bulk snapshot preserves gain, panning, and fade-in behavior while reducing mutex acquisitions. No actionable merge-blocking risk remains after normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The reviewed server path preserves existing network controls, channel ownership, and audio routing. No introduced security issue was identified. Compatibility with callers outside this repository and broader security coverage remain unverified. Retained concerns Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| } | ||
| } | ||
|
|
||
| float CChannel::GetGain ( const int iChanID ) |
|
Related: #3945 |
|
🤖 AI: The gain is measurable, and it grows with client count.
At N=12 the cycle difference sits inside ±1 sd and is not resolvable; from N=24 up it separates at every size, and The diff adds no buffer. Run-to-run spread at N=48 is six times tighter on this branch than on base, 2.9 M against 18.5 M instructions per client. No mechanism claimed for that; three reps is not an investigation. All 24 cells cleared the saturation gate — delivered packet ratio 1.010–1.011 against a 0.99 floor, none discarded, no channel ever unmixed. |
|
@mcfnord I think you can open a follow up with the other change proposed by you. Also we're missing a 2nd review here. |
|
@softins @dingodoppelt could someone of you please have a look at this? |
| return 0; | ||
| const int iChanID = vecChanIDs[j]; | ||
|
|
||
| if ( ( iChanID >= 0 ) && ( iChanID < MAX_NUM_CHANNELS ) ) |
There was a problem hiding this comment.
MathUtils::InRange could be used here.
There was a problem hiding this comment.
Yes. Agree. Will apply this in the next batch.
| { | ||
| // should not happen | ||
| vecGains[j] = 0; | ||
| vecPannings[j] = 0; |
There was a problem hiding this comment.
I'd reset the panning to 0.5 because 0 is hard left.
Looks ok to me. Agree with @dingodoppelt's couple of comments, but otherwise fine. |
|
Hmm. Pushed the changes but it doesn't show up here... |
df07df6 to
57bb17c
Compare
|
Anyway. Seems to be done now. |
| vecGains[j] = 0.5; | ||
| vecPannings[j] = 0.5; |
There was a problem hiding this comment.
| vecGains[j] = 0.5; | |
| vecPannings[j] = 0.5; | |
| vecGains[j] = 0.0; | |
| vecPannings[j] = 0.5; |
Even though this situation should not occur, I think gain should still default to 0, with only pan defaulting to 0.5
Acquire the channel mutex once per channel and copy the gain/pan values of all connected channels (compacted into the caller's channel order, with bounds guard) instead of acquiring it twice per channel pair (O(N^2) lock/unlock operations per server frame). The values are written directly into vecvecfGains/vecvecfPannings, no intermediate snapshot buffers are needed. Drop the now unused CChannel::GetGain()/GetPan(). Co-authored-by: mcfnord <mcfnord@users.noreply.github.com>
57bb17c to
4616983
Compare
|
Done. |
softins
left a comment
There was a problem hiding this comment.
Seems good to me now. Compiled and tested with gain and pan changes on a couple of channels.
Currently, we aquire a lock in GetPan, GetGain overly often in channel.cpp. We can use a one time snapshot and lock/unlock only once. Snapshotting removes constantly aquiring and releasing the Mutex which should give performance gains. Measurements suggest that it indeed gives a minor performance gain. I believe that this is safe (maybe even safer than the current code) from a concurrency viewpoint.
See AI findings/PR and more details here: ann0see#293
Short description of changes
CHANGELOG: Channel: Improve performance of getting gain and pan by using one time snapshot
Context: Fixes an issue?
Related to: #3916
Does this change need documentation? What needs to be documented and how?
No
Status of this Pull Request
Tested and measured by me and @mcfnord Needs review.
What is missing until this pull request can be merged?
Review
Checklist
AUTOBUILD: Please build all targets