-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Avoid synchronized section in CoroutineScheduler during internal pool growth #3652
Comments
I see freezes of several hundreds of milliseconds in length in UI thread. |
I was trying to figure out why on earth this synchronized section was contended up to hundreds of milliseconds. Here is the more or less self-explanatory benchmarking result:
Allocating a new thread [under a lock] is a non-trivial operation that incurs a non-trivial overhead of JVM upcalls, that may consume unpredictable (when compared to "increment, TLAB-allocate and CAS" action) amount of time that may lead to an additional contention |
The previous implementation was prone to a non-trivial contention that caused EDT freezes and, potentially, Android's ANRs. Two root causes were identified: 1) Thread() constructor that has a non-trivial complexity along with JVM upcalls and is significantly slower than any other regular allocation 2) Thread.start() is on itself a JVM upcall that ends up on a global JVM lock[s] Thread.start() is now invoked when the lock is released to reduce contention. The first root cause is not addressed as optimistic thread allocation may lead to a potential CPU waste due to how optimistically lock-less detection is and because Thread.start() is an order of magnitude slower anyway Fixes #3652
The previous implementation was prone to a non-trivial contention that caused EDT freezes and, potentially, Android's ANRs. Two root causes were identified: 1) Thread() constructor that has a non-trivial complexity along with JVM upcalls and is significantly slower than any other regular allocation 2) Thread.start() is on itself a JVM upcall that ends up on a global JVM lock[s] Thread.start() is now invoked when the lock is released to reduce contention. The first root cause is not addressed as optimistic thread allocation may lead to a potential CPU waste due to how optimistically lock-less detection is and because Thread.start() is an order of magnitude slower anyway Fixes #3652
We had multiple freeze reports from IDEA, all with the following stacktrace:
During the startup phase, IDEA aggressively launches hundreds of coroutines, and some of them are run from the main thread;
Due to the fact that the growing mechanism uses coarse-grained lock as the easiest way to avoid thread overprovision, that during contention might cause sub-ms pauses
The text was updated successfully, but these errors were encountered: