https://kotlinlang.org logo
#coroutines
Title
# coroutines
e

Edoardo Luppi

03/27/2024, 10:44 AM
Unrelated to coroutines, but I was looking at the code for
limitedParallelism
, and found that the int value is checked with
Copy code
// Save a few bytecode ops
internal fun Int.checkParallelism() = require(this >= 1) { "Expected positive parallelism level, but got $this" }
Was this done because of bytecode size limitations of the Android platform? Or because of something else?
b

bezrukov

03/27/2024, 11:49 AM
I would guess it is virtual call vs setting up a thread for a possible exception. So basically it forces
require(...)
to not be inlined
j

jw

03/27/2024, 12:05 PM
Yes, but it becomes a static call in the bytecode. There's also no threads involved for exceptions. It moves the conditional, exception instantiation, and string builder code to a single location. The call sites only have the single invoke static.