diff --git a/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/serialization/KotlinFacetSettingsWorkspaceModel.kt b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/serialization/KotlinFacetSettingsWorkspaceModel.kt index 4bb6398dc08c..37b103d6da45 100644 --- a/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/serialization/KotlinFacetSettingsWorkspaceModel.kt +++ b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/serialization/KotlinFacetSettingsWorkspaceModel.kt @@ -49,23 +49,29 @@ class KotlinFacetSettingsWorkspaceModel(val entity: KotlinSettingsEntity.Builder } private var _compilerArguments: CommonCompilerArguments? = null + private var _lastKnownCompilerArguments: String? = null override var compilerArguments: CommonCompilerArguments? get() { - if (_compilerArguments != null) { + val currentSerializedArguments = entity.compilerArguments + if (_compilerArguments != null && currentSerializedArguments == _lastKnownCompilerArguments) { + // Cache is valid, return the cached value return _compilerArguments } - val serializedArguments = entity.compilerArguments - _compilerArguments = serializedArguments?.let { + // Deserialize and update the cache + _compilerArguments = currentSerializedArguments?.let { CompilerArgumentsSerializer.deserializeFromString(it) } + _lastKnownCompilerArguments = currentSerializedArguments return _compilerArguments } set(value) { - entity.compilerArguments = CompilerArgumentsSerializer.serializeToString(value) + val serializedValue = CompilerArgumentsSerializer.serializeToString(value) + entity.compilerArguments = serializedValue updateMergedArguments() _compilerArguments = value?.unfrozen() + _lastKnownCompilerArguments = serializedValue } override val mergedCompilerArguments: CommonCompilerArguments?