Skip to content

Replace per-pair gain/pan mutex locking with snapshot - #3948

Open
ann0see wants to merge 2 commits into
jamulussoftware:mainfrom
ann0see:perf/server-gain-pan-snapshot
Open

ann0see wants to merge 2 commits into
jamulussoftware:mainfrom
ann0see:perf/server-gain-pan-snapshot

Conversation

@ann0see

@ann0see ann0see commented Sep 13, 2026

Copy link
Copy Markdown
Member

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

  • I've verified that this Pull Request follows the general code principles
  • I tested my code and it does what I want
  • My code follows the style guide
  • I waited some time after this Pull Request was opened and all GitHub checks completed without errors.
  • I've filled all the content above

AUTOBUILD: Please build all targets

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>
@ann0see ann0see added refactoring Non-behavioural changes, Code cleanup AI AI generated or potentially AI generated labels Sep 13, 2026
@ann0see ann0see added this to Tracking Sep 13, 2026
@github-project-automation github-project-automation Bot moved this to Triage in Tracking Sep 13, 2026
@ann0see
ann0see requested a review from softins September 13, 2026 09:50
@coderabbitai

coderabbitai Bot commented Sep 13, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: QUIET

Plan: Advanced

Run ID: 315c20b2-8d54-476f-ada3-1f40c2c7c065

📥 Commits

Reviewing files that changed from the base of the PR and between 6a64db4 and df07df6.

📒 Files selected for processing (1)
  • src/server.cpp

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

CChannel replaces single-channel gain and pan accessors with a bulk method. CServer::DecodeReceiveData uses the method to populate gains and pannings for connected channels while retaining fade-in gain processing.

Changes

Channel gain and panning retrieval

Layer / File(s) Summary
Bulk retrieval API
src/channel.h, src/channel.cpp
CChannel replaces GetGain and GetPan with GetGainsAndPannings, which fills output vectors under Mutex and writes zero for out-of-range channel IDs.
Server integration
src/server.cpp
CServer::DecodeReceiveData uses the bulk method to populate gain and panning arrays. The existing fade-in gain multiplication remains unchanged.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: pljones

Merge Risk: ⚪ Minimal · up to df07d

No actionable merge-blocking risk is identified in this change.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description follows the repository template. It explains the snapshot-based mutex change, changelog impact, issue context, documentation status, testing status, remaining review work, and checklis…
Title check ✅ Passed The title clearly summarizes the primary change: replacing repeated gain and pan mutex locking with a single snapshot.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread src/channel.cpp
}
}

float CChannel::GetGain ( const int iChanID )

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed

@ann0see

ann0see commented Sep 13, 2026

Copy link
Copy Markdown
Member Author

Related: #3945

@ann0see ann0see moved this from Triage to Waiting on Team in Tracking Sep 13, 2026
Comment thread src/server.cpp
Comment thread src/server.cpp Outdated
@ann0see ann0see added this to the Release 4.0.0 milestone Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI AI generated or potentially AI generated refactoring Non-behavioural changes, Code cleanup

Projects

Status: Waiting on Team

Development

Successfully merging this pull request may close these issues.

2 participants