-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve algorithm to find in use channels in O(n) instead O(n²) #2738
Improve algorithm to find in use channels in O(n) instead O(n²) #2738
Conversation
src/audiomixerboard.cpp
Outdated
{ | ||
// if current fader is not used, hide it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a bit redundant here
Own channel first doesn't seem to work correctly at the moment: If we set the own channel checkbox, nothing happens at first. You need to set a ordering first. It's not reproducible; At least it only appeared on the first launch of the app. Also setting ini files doesn't seem to get the issue back. |
Note that a lot of the code in audiomixerboard.cpp (GUI only) needs moving into a non-GUI class, so that state is not being maintained in the GUI. Any large scale restructuring should take that into account as one of its (main) goals. |
524ff43
to
2e078e4
Compare
Doesn't surprise me. A lot of the code is impentrable. Hence I'd rather a full refactor than trying to "fix in place". |
This PR is mainly about implementing the algorithm we used for the gain reset here in the GUI too; not that much about a separation into a second class. I still think it's worth merging this one? However, what exactly do you want to get extracted into another class? |
Ok. I can confirm that own fader first is broken by this change. This needs more investigation. |
src/audiomixerboard.cpp
Outdated
// check if this is my own fader and set fader property | ||
if ( i == iMyChannelID ) | ||
{ | ||
vecpChanFader[i]->SetIsMyOwnFader(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite get why the new approach breaks the own fader first logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see it either. The refactoring looks correct to me.
Are you sure that this PR broke it? I've just tested with 3.8.2 and it seems to be broken there as well, unless I'm testing the wrong thing? :o
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested anything before that, but I don't remember that own fader first didn't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3.8.2 was the first release which contained it. #1809 was the PR. I'm currently looking into it and will open a separate issue if necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I had reproduced the own-fader-first-breakage with this PR and then with a clean 3.8.2 build. Now I can no longer reproduce it either way. Everything works fine and I'm not sure what I'm doing differently now.
@ann0see Can you share how you made it break?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's related to a fresh start without sorting and then enabling own fader first.
Not sure, but the following could lead to the issue (untested):
- Connect to a crowded server without sorting
- Wait until someone joins
- Set own fader first
- Observe you aren't first
Yep. In the mean time, we should merge any iterative improvements such as this PR (once proven correct... ;)) neverthless, in my opinion. |
728b2c0
to
0eeae20
Compare
Now I seem to miss a new join (fader doesn't show up) with the same (empty) name. This clearly needs more testing |
6d94d5b
to
562acb5
Compare
Could it be related to that? |
Probably they're not related to the change in my PR at all (but still need to be investigated.) Can you reproduce any of them on Linux? |
Line 1200: why is this not in the mutex? Can we guarantee the number of clients doesn't change before we acquire the lock? |
Actually, reading your "how to reproduce", I don't think own fader first has ever worked. I generally don't use sort and I turned off the own fader first feature once I realised it didn't work. |
Actually I can’t reproduce it anymore. That’s the issue. Sometimes it works, sometimes it doesn’t. Maybe it’s worth looking at the initial PR again. |
Yes, that's the same behaviour I've always had - I see it, then when I try to get a reliable way to reproduce it, I can't. |
I just re-checked, at least one of both bugs also shows up on the current 3.8.2 release, so it's unrelated. |
src/audiomixerboard.cpp
Outdated
{ | ||
if ( iFaderNumber[iChanID] == INVALID_INDEX ) | ||
{ | ||
// fader is not used --> hide it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1232/1233 could be rewritten to flow better. "Hide it." "Oh wait!! Before that, just one thing - store the levels. Oh!! Only of certain conditions are met."
So first we store the levels (I don't think the "if some..." is needed - that's the concern of the called method - though maybe the method name needs improving at some point), then we hide the fader. The comment should reflect that.
However..! I don't even think the comment is adding to the code here. "Store...; ...Hide()" is fairly self-explanatory (as the vector name is good).
A simple // fader is not used
to describe the case would do.
src/audiomixerboard.cpp
Outdated
} | ||
|
||
// current fader is used | ||
// check if fader was already in use -> preserve gain value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment (line 1241) should move inside the if
. Then the "check if" can be removed (and a "not" added). That makes it more or less a duplicate of line 1244. I'd put the "reset everything" part of 1244 on its own line, though.
Also ... "-> preserve gain value" appears to refer to the code at line 1277 - so really shouldn't be here.
src/audiomixerboard.cpp
Outdated
vecpChanFader[iChanID]->Reset(); | ||
vecAvgLevels[iChanID] = 0.0f; | ||
|
||
// check if this is my own fader and set fader property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't say "check if" on an if statement. That's what an if statement is. Inside the if -- if the test doesn't make it clear -- explain the state. Here, a comment of "// this is my own fader" would be present. However, it's pretty redundant.
src/audiomixerboard.cpp
Outdated
vecpChanFader[iChanID]->SetIsMyOwnFader(); | ||
} | ||
|
||
// set and increment the running new client counter needed for sorting (per definition: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment doesn't really help...
Something as brief as
// keep track of each new client (for "no sorting" channel sort order, new clients are added to the right-hand side of the mixer)
might do.
src/audiomixerboard.cpp
Outdated
} | ||
} | ||
|
||
// if current fader is not used, hide it | ||
if ( !bFaderIsUsed ) | ||
// restore gain (if new name is different from the current one) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, again, is a duplicate comment -- the comment should be inside the if describing the state there. There's already a comment which does that in the right place.
Sorry, just went through in "picky" mode. As there are a lot of changes happening, it might be nice to make the comments clear at the same time. |
00bd916
to
e2f4344
Compare
No problem. I just added another commit. |
e2f4344
to
997a387
Compare
src/audiomixerboard.cpp
Outdated
@@ -1210,92 +1210,97 @@ void CAudioMixerBoard::ApplyNewConClientList ( CVector<CChannelInfo>& vecChanInf | |||
|
|||
// search for channels with are already present and preserve their gain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^with^which
Approved but if you want to fix the existing typo, please do. |
997a387
to
824cfed
Compare
This replaces the O(n²) approach to find channels in use with a simpler O(n) approach.
Co-Authored-By: Peter L Jones <pljones@users.noreply.github.com>
824cfed
to
603cea1
Compare
Short description of changes
This replaces the O(n²) approach to find channels in use with a simpler O(n) approach.
Probably there are other places which would benefit from a more efficient approach too.
CHANGELOG: Client: Improve performance of GUI when someone join or leave a server.
Context: Fixes an issue?
Related to: #2737 (comment)
Does this change need documentation? What needs to be documented and how?
No.
Status of this Pull Request
Close performance evaluation and (in depth) testing:
What is missing until this pull request can be merged?
Testing
Checklist