-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Implement internal API for running current event loop #3641
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
Conversation
2bc6b26
to
b3c46ec
Compare
while (start != end && blockingTasksInBuffer.value > 0) { | ||
val task = tryExtractBlockingTask(--end) | ||
// CPU or (BLOCKING & hasBlocking) | ||
val shouldProceed = !onlyBlocking || blockingTasksInBuffer.value > 0 |
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.
shouldProceed
isn't updated deliberately, I find making it as part of while
a bit more compact
kotlinx-coroutines-core/common/src/internal/LimitedDispatcher.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Dmitry Khalanskiy <[email protected]>
Co-authored-by: Dmitry Khalanskiy <[email protected]>
Co-authored-by: Dmitry Khalanskiy <[email protected]>
Co-authored-by: Dmitry Khalanskiy <[email protected]>
Co-authored-by: Dmitry Khalanskiy <[email protected]>
while (start != end && blockingTasksInBuffer.value > 0) { | ||
val task = tryExtractBlockingTask(--end) | ||
// Bail out if there is no blocking work for us | ||
if (onlyBlocking && blockingTasksInBuffer.value == 0) return null |
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.
It is still a mystery to me why we don't do it on every iteration any longer. Could you drop a comment in the code?
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.
My idea was to check it once and then look for the task. The only scenario where the task is not found is when another thread decides to steal a blocking task from the very same queue, which is not very likely. Effectively, I traded a negligible part of "slow path" ("unlikely event happened") performance for the same negligible benefit on "fast path".
It's unlikely to matter in reality, so readability/maintainability must be preferred; I'll rollback the change
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 particular place still has the change.
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.
Also, I would be okay with it if it had a corresponding comment and, preferably, was in a separate commit (this one is a bit loaded with changes already).
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.
Oh, I probably have to stop pushing any changes around Friday's evenings 😅
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.
Alternatively, you could embrace the flow, go for it, and publish a release today.
while (start != end && blockingTasksInBuffer.value > 0) { | ||
val task = tryExtractBlockingTask(--end) | ||
// Bail out if there is no blocking work for us | ||
if (onlyBlocking && blockingTasksInBuffer.value == 0) return null |
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.
Also, I would be okay with it if it had a corresponding comment and, preferably, was in a separate commit (this one is a bit loaded with changes already).
Fixes #3439