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
Make all workers run on the Unconfined dispatcher. #851
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zach-klippenstein
force-pushed
the
zachklipp/named-worker-coroutines
branch
2 times, most recently
from
December 24, 2019 20:05
51cb696
to
5467ed0
Compare
zach-klippenstein
force-pushed
the
zachklipp/unconfined-workers
branch
from
December 24, 2019 20:07
f32b4da
to
49fe5f8
Compare
rjrjr
approved these changes
Jan 8, 2020
kotlin/workflow-core/src/main/java/com/squareup/workflow/Worker.kt
Outdated
Show resolved
Hide resolved
zach-klippenstein
force-pushed
the
zachklipp/unconfined-workers
branch
from
January 8, 2020 17:53
49fe5f8
to
a0657a6
Compare
zach-klippenstein
changed the base branch from
zachklipp/named-worker-coroutines
to
master
January 8, 2020 17:54
zach-klippenstein
force-pushed
the
zachklipp/unconfined-workers
branch
from
January 8, 2020 17:55
a0657a6
to
ebfa3d3
Compare
zach-klippenstein
added a commit
that referenced
this pull request
Feb 6, 2020
This is helpful for tests that need to be able to control time. This functionality was covered by the test's dispatcher, but since #851 changed the dispatcher used for workers, we need to be able to configure workers' contexts separately.
2 tasks
zach-klippenstein
added a commit
to square/workflow-kotlin
that referenced
this pull request
Jun 20, 2020
First part of Kotlin implementation of square/workflow#1021. Kotlin counterpart to square/workflow#1174. This implementation intentionally does not run the side effect coroutine on the `workerContext` `CoroutineContext` that is threaded through the runtime for testing infrastructure. Initially, workers ran in the same context as the workflow runtime. The behavior of running workers on a different dispatcher by default (`Unconfined`) was introduced in square/workflow#851 as an optimization to reduce the overhead for running workers that only perform wiring tasks with other async libraries. This was a theoretical optimization, since running on the `Unconfined` dispatcher inherently involves less dispatching work, but the overhead of dispatching wiring coroutines was never actually shown to be a problem. Additionally, because tests often need to be in full control of dispatchers, the ability to override the context used for workers was introduced in square/workflow#940, which introduced `workerContext`. I am dropping that complexity here because it adds a decent amount of complexity to worker/side effect machinery without any proven value. It is also complexity that needs to be documented, and is probably just more confusing than anything. The old behavior for workers is maintained for now to reduce the risk of this change, but side effects will always run in the workflow runtime's context. This is nice and simple and unsurprising and easy to reason about.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
From the kdoc:
Previously, the workers would run on the same dispatcher as the workflow runtime (
Main.immediate
), which meant that if the worker was wrapping, e.g., anObservable
that was emitting on a background thread, the coroutine would dispatch back onto the main thread before sending to the channel, which is completely unnecessary, since channels are already thread-safe.This doesn't change the threading behavior for simple side-effect-only workers – since they're started from the workflow runtime, they will be dispatched onto the nested event loop that
Main.immediate
creates for "immediate" dispatches.