diff --git a/plugins/grazie/src/main/kotlin/com/intellij/grazie/cloud/DependencyParser.kt b/plugins/grazie/src/main/kotlin/com/intellij/grazie/cloud/DependencyParser.kt index 2a00c103eac9..9970aa56a662 100644 --- a/plugins/grazie/src/main/kotlin/com/intellij/grazie/cloud/DependencyParser.kt +++ b/plugins/grazie/src/main/kotlin/com/intellij/grazie/cloud/DependencyParser.kt @@ -34,6 +34,7 @@ import org.languagetool.language.English object DependencyParser { private val LOG = Logger.getInstance(DependencyParser::class.java) + private val cachedTrees = ContainerUtil.createSoftKeySoftValueMap() @JvmStatic fun getParser(text: TextContent, minimal: Boolean): AsyncBatchParser? { @@ -62,7 +63,11 @@ object DependencyParser { val support = obtainSupport(language) if (support != null) { @Suppress("UNCHECKED_CAST") - return sentences.associateWith { Tree.createFlatTree(support, it.sentence) } as LinkedHashMap + return sentences.associateWith { + cachedTrees.getOrPut(it.sentence) { + Tree.createFlatTree(support, it.sentence) + } + } as LinkedHashMap } return LinkedHashMap()