-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Twitter dont block main on file ops #7298
Twitter dont block main on file ops #7298
Conversation
On initialization, a promise is created that synchronously waits on an NSOperationQueue with file ops in it. Re-work this so that the promise is asynchronously fulfilled with an operation that is inserted into the queue, and then dispatched back to the main queue when finished.
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
Hi! We'd like to get a build of Firebase into the Twitter app release that cuts its branch this week. We can cherry-pick it if necessary, but I thought I would give a friendly nudge here, first. We have another PR here that the same applies to: #7302 Thanks! |
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.
@jhollida24 Thank you for your contribution! The change looks good to me.
@samedson @elenadoty Could you please provide review from your end.
@@ -410,10 +410,18 @@ - (FBLPromise *)deleteUnsentReports { | |||
NSOperationQueue *__weak queue = _operationQueue; | |||
FBLPromise *__weak unsentReportsHandled = _unsentReportsHandled; | |||
promise = [promise then:^id _Nullable(NSNumber *_Nullable 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.
optional: I wonder if a version below would be a bit more readable?
promise = [promise onQueue:dispatch_get_global_queue(QOS_CLASS_UTILITY, 0) then:^id _Nullable(NSNumber *_Nullable value) {
[queue waitUntilAllOperationsAreFinished];
return value;
}
.then(^id _Nullable(NSNumber *_Nullable value) {
[unsentReportsHandled fulfill:nil];
return 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.
I'm happy to make changes that you would like, but I think the GCD folks at Apple would discourage this. Dispatching work to the global concurrent queues that blocks causes dispatch worker threads to be created (for the next block coming through), which is then torn down when it's unblocked. An additional operation on an existing (serial) queue doesn't expand the total concurrency.
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 do agree with you it's more readable, and it's nice that it doesn't rely on the automatic flatMap behavior of FBLPromise.
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.
Good point on blocking a global queue - agreed it's not the best idea. Current version looks good to me from logic perspective. I'll think how we can improve readability and comment if I have any ideas.
@@ -410,10 +410,18 @@ - (FBLPromise *)deleteUnsentReports { | |||
NSOperationQueue *__weak queue = _operationQueue; | |||
FBLPromise *__weak unsentReportsHandled = _unsentReportsHandled; | |||
promise = [promise then:^id _Nullable(NSNumber *_Nullable value) { | |||
[queue waitUntilAllOperationsAreFinished]; |
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.
@samedson @elenadoty Do you remember if blocking UI thread is intentional here or just an accident?
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 believe this was an oversight. It shouldn't be a problem to delete in the background
Hello. We see the code referenced here blocking the main thread at startup and causing our watchdog system to kill the app. Synchronously waiting for filesystem operations to complete from the main thread can be safely removed.