From 3f6f508cccdb8fe5282d765a199154e496da8cee Mon Sep 17 00:00:00 2001 From: Roman Golyshev Date: Tue, 25 Feb 2025 17:09:47 +0100 Subject: [PATCH] KTIJ-33008 [coroutines] Use `StringBuilder` instead of string concatenation to render `CoroutineContext` Since there might be a lot of elements in the `CoroutineContext`, joining them with string concatenation in a cycle basically means O(N^2) performance GitOrigin-RevId: fe5652f0ff9b0abb43320fc7dd4d18f3118f2f38 --- .../base/src/com/intellij/diagnostic/coroutineDumper.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/platform/util/base/src/com/intellij/diagnostic/coroutineDumper.kt b/platform/util/base/src/com/intellij/diagnostic/coroutineDumper.kt index fa0fb17f8ea5..7a39dfa200f6 100644 --- a/platform/util/base/src/com/intellij/diagnostic/coroutineDumper.kt +++ b/platform/util/base/src/com/intellij/diagnostic/coroutineDumper.kt @@ -336,9 +336,12 @@ private fun traceToDump(info: DebugCoroutineInfo, stripTrace: Boolean): List - if (acc.isEmpty()) element.toString() else "$acc, $element" - } + this.fold(StringBuilder()) { acc, element -> + if (acc.isNotEmpty()) { + acc.append(", ") + } + acc.append(element.toString()) + }.toString() private fun MutableSet.withElement(elem: T, body: (added: Boolean) -> R): R { val added = add(elem)