Hello, I'm creating a CommonMark parser (<spec.com...
# coroutines
m
Hello, I'm creating a CommonMark parser (spec.commonmark.com) and the second stage is being done in parallel, the second stage is where inlines are parsed from blocks, I've noticed that if I have a large number of blocks (say 1000) and I launch them into a coroutine about 20% of my runtime is actually switching coroutine contexts. This is obviously not ideal and I was wondering if anyone knew how to make it so that each 'job' is ran until it is completed then the next 'job' is picked up
o
that already happens as much as possible, if you're switching dispatchers it'd be quite inefficient and cumbersome to block your previous dispatcher from running anything at all
if you're not switching dispatchers, no suspension happens at all iirc
m
this is the flamegraph I am getting, (above the blue is where I'm assuming context switching is happening) from what you said, this would be the completion of one job and the thread changing context to the next job?
Copy code
private suspend fun parseLeaves(leaves: List<Leaf>){
        coroutineScope {
            // launches all leaves into seperate coroutines to be dealt with as they can
            leaves.forEach { launch { analyzeBlock(it) } }
        }
    }
Is how Im launching my coroutines
o
if you're getting a thread name change every context switch, you likely left the kotlin coroutines debug flag on
m
ugh lol
how do i turn that off? mostly debugging but trying to see performance
Doing a report for school on my perofrmance vs other implementations
m
thanks so much!