-
Notifications
You must be signed in to change notification settings - Fork 103
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
Create a background serial queue and run RPC notifications on it #813
Create a background serial queue and run RPC notifications on it #813
Conversation
As a followup to the evolution proposal discussion on this - I have a couple of comments/concerns regarding the implementation of this change:
|
Hi Nick, thanks for the feedback.
|
1 can probably be mitigated through appropriate documentation, but 2 is still a concern. I agree that 3 is probably a larger task and beyond the scope of this PR, I just wanted to make sure it was called out as a potential way to further address what I understand to be the issue motivating this change. |
|
|
__block BOOL presented = NO; | ||
dispatch_sync(dispatch_get_main_queue(), ^{ | ||
presented = (self.viewController.isViewLoaded && (self.viewController.view.window || self.viewController.isBeingPresented)); | ||
}); |
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.
Calling dispatch_sync(dispatch_get_main_queue()
while on the main thread causes deadlock and the app crashes
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.
Screen touches are much more responsive. The only issue I had was the app crash noted in the comment.
I am getting UI API called from background thread Group warnings for the following lines in the
|
BTW, I updated it to make sure no response processing happens on the main queue. |
I like the change to move the processing queue into the proxy, definitely seems like this should help with responsiveness. |
This is only true because callbacks were done on main.
This is true, but IMO it would be as likely to have been called on main as on an arbitrary thread. While this technically reduces the odds of it happening all on main, we have tested extensively with a comprehensive SDL media app and have seen no issues with the new behavior.
This is a very minor point in the whole discussion. For clarity, I'm saying that to write to a thread-safe dictionary would look like: - (void)writeKey:(id<NSCopying>)key value:(id)value {
dispatch_async(_dictQueue, ^{
dict[key] = value;
});
} Read: - (id)readValueForKey:(id<NSCopying>)key {
__block id value = nil;
dispatch_sync(_dictQueue, ^{
value = dict[key];
});
return value;
}
The original motivation was due to CarWindow. Touch events come back very rapidly (before this PR) on the main queue. The dev then has to update their UI based on those touch events on the main queue, while CarWindow screenshots on the main queue. The intent of this PR was to move those touch events to the background, freeing up the main queue for that CarWindow work, and it does this job. The fact that it seems to improve other apps is a secondary, but welcome, change. I'm not under the illusion that this is a final fix, but from experience with the library and testing, it does appear to be a band-aid. |
It looks like this was merged, so I'll leave a final summary thoughts on this:
Yes, this is the basis for my argument. The main queue is public, and intentionally or not, the previous implementation dictated how clients could use the library's API in a way that was A) (mostly) safe, B) did not require extra synchronization their side. Following this, neither of these things are possible.
Possibly. I can't speak for other clients, but in our interaction with the library we noticed that calling in on background threads introduced stability issues, and adjusted our call pattern accordingly.
I was suggesting wrapping the entire interaction in an async block earlier in the call stack, so making the dictionary itself thread-safe wouldn't be necessary. The reason I'm stressing this point is that (assuming it wouldn't introduce other problems) it looks it may be possible to address my worst safety concerns quickly by dispatching the logic in
Pushing events to clients on a different queue so they don't interfere with other work is what I'm suggesting. The current approach mitigates the problem by shifting it on to the notification queue, which I think this is fine as a stop-gap (assuming it's done in a way that doesn't introduce other issues,) but a more comprehensive fix is possible. It sounds like we're in agreement on this point at least. |
Fixes #798
This PR is ready for review.
Risk
This PR makes no API changes.
This would cause differences in behavior on RPC returns. If developers make UI changes (or have code dependent on the main queue), runtime code errors could occur.
Testing Plan
n/a
Summary
Move RPC notifications from the main queue to a background serial queue.
Changelog
Enhancements
Tasks Remaining:
dispatch_main
CLA