From af96c735bb03d4c0b93e58a611dd1080182b5ca5 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 15 Dec 2022 14:43:28 +0100 Subject: [PATCH] K2: use PUBLICATION mode for lazy members in KtSourceElement This commit removes performance problems during these members access --- .../src/org/jetbrains/kotlin/KtSourceElement.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/frontend.common/src/org/jetbrains/kotlin/KtSourceElement.kt b/compiler/frontend.common/src/org/jetbrains/kotlin/KtSourceElement.kt index d13333d6e93..4334b64dbd3 100644 --- a/compiler/frontend.common/src/org/jetbrains/kotlin/KtSourceElement.kt +++ b/compiler/frontend.common/src/org/jetbrains/kotlin/KtSourceElement.kt @@ -284,9 +284,13 @@ sealed class KtPsiSourceElement(val psi: PsiElement) : KtSourceElement() { override val endOffset: Int get() = psi.textRange.endOffset - override val lighterASTNode by lazy { TreeBackedLighterAST.wrap(psi.node) } + override val lighterASTNode: LighterASTNode by lazy(LazyThreadSafetyMode.PUBLICATION) { + TreeBackedLighterAST.wrap(psi.node) + } - override val treeStructure: FlyweightCapableTreeStructure by lazy { WrappedTreeStructure(psi.containingFile) } + override val treeStructure: FlyweightCapableTreeStructure by lazy(LazyThreadSafetyMode.PUBLICATION) { + WrappedTreeStructure(psi.containingFile) + } internal class WrappedTreeStructure(file: PsiFile) : FlyweightCapableTreeStructure { private val lighterAST = TreeBackedLighterAST(file.node)