You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class DebugProbesTest : DebugTestBase() {
fun <Node> generateRecursiveSequence(initialSequence: Sequence<Node>, children: (Node) -> Sequence<Node>): Sequence<Node> {
return sequence {
val initialIterator = initialSequence.iterator()
if (!initialIterator.hasNext()) {
return@sequence
}
val visited = HashSet<Node>()
val sequences = ArrayDeque<Sequence<Node>>()
sequences.addLast(initialIterator.asSequence())
while (sequences.isNotEmpty()) {
val currentSequence = sequences.removeFirst()
for (node in currentSequence) {
if (visited.add(node)) {
yield(node)
sequences.addLast(children(node))
}
}
}
}
}
@Volatile
var a = 2
@Test
fun stressGenerateRecursive() {
while (true) {
runBlocking {
repeat(8) {
launch(Dispatchers.Default) {
val seq = generateRecursiveSequence((1..100).asSequence()) {
(1..it).asSequence()
}
for (i in seq) {
a = i
}
}
}
}
}
}
}
Profile:
Up to 30% is occupied by updateState
The text was updated successfully, but these errors were encountered:
It seems like a ReentrantLock is a rudiment from pre-concurrent implementation times.
It indeed incurs some non-trivial overhead, while providing only a single benefit -- strongly consistent snapshot in read operations (dump/hierarchyToString etc.). The guarantee seems to be way too strong for such an overhead, and the proposed solution is just to remove this lock.
The trick here is to ensure that we do have a proper ordered access to memory locations everywhere
Snippet to reproduce:
Profile:
Up to 30% is occupied by
updateState
The text was updated successfully, but these errors were encountered: