From cecf22e035de0c557a1a8e9ac0cce3071f5953e6 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Mon, 27 Feb 2023 16:38:39 +0100 Subject: [PATCH] Fix application environment keepalive handling The previous changes to the disposer registration changes introduced a weird problem exposed in the Gradle (test?) environment, that caused a performance regression - it seems that keep alive system property in that setting was cleared at the time the disposer was called, causing app env disposal when keeping it alive was expected. This fix captures property value at the moment of disposer registration, making it similar in that respect to the previous variant and avoiding the performance degradation. #KT-56992 fixed --- .../kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt index ae2e382b809..d7312fb9444 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt @@ -515,6 +515,8 @@ class KotlinCoreEnvironment private constructor( }) } try { + val disposeAppEnv = + CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.value.toBooleanLenient() != true // Disposer uses identity of passed object to deduplicate registered disposables // We should everytime pass new instance to avoid un-registering from previous one @Suppress("ObjectLiteralToLambda") @@ -528,7 +530,7 @@ class KotlinCoreEnvironment private constructor( // Do not use this property unless you sure need it, causes Application to MEMORY LEAK // Only valid use-case is when Application should be cached to avoid // initialization costs - if (CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.value.toBooleanLenient() != true) { + if (disposeAppEnv) { disposeApplicationEnvironment() } else { ourApplicationEnvironment?.idleCleanup()