question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optimize `runBlocking` and `EventLoop` implementations

See original GitHub issue
  • EventLoopBase implementation class should allocate both queue and delayed lazily, moreover, a queue shall not be allocated as long as there is at most one queued task (optimization that is similar to JobSupport)
  • DispatchedContinuation shall extend QueuedTask, so that common case of EventLoop usage does not involve creation of objects at all.
  • Consider providing a reusable version of EventLoop implementation, so that performance-sensitive code can create a single instance that is reused for multiple sequential invocations of runBlocking.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
elizarovcommented, Dec 19, 2017

No. Saving small object to ThreadLocal is usually counter-productive. Access to ThreadLocal is typically more expensive than allocation/collection of small objects. TheadLocal pooling is usually beneficial only for very large objects.

0reactions
qwwdfsadcommented, Jun 26, 2018

@tr8dr in general sendBlocking and offer have the same performance if send doesn’t suspend (aka there is enough buffer capacity), because internally it has the same (if (!offer()) { runBlocking {...}}) check.

For cases when channel capacity is saturated you should measure your performance on your specific workload because numbers out of thin air (“on my artificial benchmark sendBlocking is two times slower”) are mostly useless

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding Kotlin coroutines - LogRocket Blog
Dive deeper into Kotlin coroutines — suspendable computations similar to threads that simplify asynchronous programming in Kotlin.
Read more >
Doc: Is it correct that the thread running runBlocking blocks?
Runs a new coroutine and blocks the current thread until its completion. This function should not be used from a coroutine. It is...
Read more >
Change log for kotlinx.coroutines
runBlocking and EventLoop implementations optimized (see #190). Version 0.20. Migrated to Kotlin 1.2.0. Channels: Sequence-like filter , ...
Read more >
How runBlocking May Surprise You - ProAndroidDev
This happens because runOnUiThread uses optimization by checking the current thread. If the current thread (UI thread in this case) is the same ......
Read more >
How to Prevent Reactive Java Applications from Stalling
Traditional Java applications run blocking code and a common approach ... need to worry about the event loop freezing up (reactor meltdown).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found