-
Notifications
You must be signed in to change notification settings - Fork 908
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
Deprecate existing WorkerBinder.bind methods and provide recommended bindTo methods with RibDispatchers.Default #594
Conversation
80d64b9
to
a4eb507
Compare
Deprecates existing WorkerBinder.bind methods that currently defaults to RibDispatchers.Unconfined in favor of bindInteractor/binPresenter methods that will be bound by default off the main thread (Worker still can override this binding individually if needed)
a4eb507
to
af354f2
Compare
android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerBinder.kt
Outdated
Show resolved
Hide resolved
android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerBinder.kt
Outdated
Show resolved
Hide resolved
android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerBinder.kt
Outdated
Show resolved
Hide resolved
android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerBinder.kt
Outdated
Show resolved
Hide resolved
android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerBinder.kt
Outdated
Show resolved
Hide resolved
android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerBinder.kt
Outdated
Show resolved
Hide resolved
This comment was marked as outdated.
This comment was marked as outdated.
97e452a
to
5a58c21
Compare
5a58c21
to
60660e8
Compare
fb98a37
to
2759b49
Compare
android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerBinder.kt
Outdated
Show resolved
Hide resolved
* @return [WorkerUnbinder] to unbind [Worker]'s lifecycle. | ||
*/ | ||
@JvmStatic | ||
public fun bindToPresenter( |
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 looks like new functionality added that isn't needed for these changes (unless I missed it's usage) where we support binding to a list.
- Should this be a separate PR if we want a new puiblic API.
- Rather in this diff or on the next, probably rename to bindToPresenters (plural)
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.
We've been providing these APIs (WorkerBinder.bind(interactor, listOfWorkers)/ WorkerBinder.bind(presenter, listOfWorkers) for a while.
Part of the goal of this PR is to deprecate existing WorkerBinder.bind methods given that the methods with 2 parameter call takes a default RibDispatchers.Unconfined which often times results in binding on main thread.
Was thinking that adding new methods (bindToInteractor, bindToPresenter) that are opinionated on using to RibDispatchers.Default to prevent further additions of WorkerBinder.bind on main thread (we can easily rely on static analysis to force everyone to use the new API when new WorkerBinder additions).
Also another important caveat, if there is still a need for a legacy worker to be bound on the main thread this can be achieved by overriding Worker's coroutineContext property (this will ignore the default Dispatchers specified on WorkerBinder call)
1b1b4e8
to
27364b1
Compare
27364b1
to
1cfca74
Compare
android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerBinder.kt
Outdated
Show resolved
Hide resolved
android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerBinder.kt
Outdated
Show resolved
Hide resolved
Revert "Move extensions functions to its own file" This reverts commit 675fdf4e77cfd550658bc4a3989824dd79308b87.
675fdf4
to
9bf6e89
Compare
I don't have any conceptual objections. Exposing new API as public top-level function instead of nested inside With that said, maybe we should consider deprecating |
I completely agree with eventually fully deprecating this old worker. The only missing piece for RibCoroutineWorker is monitoring option for binding duration (but given that by default is bound on RibDispatchers.Default. there is no much of a concern). Also we can validate a few of this RibCoroutineWorkers in prod and if no issues found we can completely mark worker as deprecated |
Actually, after thinking about a bit more I don't think we should keep expanding this WorkerBinder API given is going to be deprecated soon in favor of RibCoroutineWorker. I was thinking though to add a migration mechanism to change the WorkerBinderDispatcher to other than Unconfined. In that manner we can migrate internally all worker binding outside Ui thread in a safe manner |
Will be putting a new PR for migration API options |
Description:
Since #553 we added support to specify on which CoroutineDispatcher are presidio Worker will be bound. RibDispatchers.Unconfined was added as a default parameter in order to keep existing behavior and not be a breaking change.
Still, binding by default on the current caller thread within interactor means that by default we are binding workers on main UI thread leading to potential jank ANR etc just for binding those workers.
This is specially problematic when the list of workers being bound keeps increasing (e.g. hypothetically if we have 100 workers and each bind takes at least 50 ms this will result on the UI thread being blocked for at least 5000ms)
Proposal is to deprecate existing methods and provide new methods that by default will bind on Ribdispatchers.DEFAULT (similarly to RibCoroutineWorker). Still if there is a need for a Worker to change the thread where it will be bound we can rely on coroutineContext property to be overriden as following (default value is EmptyCoroutineContext):
Demo call:
worker.bindTo(interactor)
NOTE: For calling on existing java files ->
WorkerBinderKt.bindTo(ribWorker, this));
Related issue(s):
#595
Verified via Unit tests