Skip to content

Commit

Permalink
[Perf] Remove the duplicated notifyCompilerInitialized call for JVM…
Browse files Browse the repository at this point in the history
… Psi

Add the missing `notifyCompilerInitialized` call for a compilation with a config error
  • Loading branch information
KvanTTT authored and Space Team committed Feb 12, 2025
1 parent 7168c69 commit 9fddcf0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
14 changes: 8 additions & 6 deletions compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
val environment = createCoreEnvironment(
rootDisposable, configuration, messageCollector,
moduleChunk.targetDescription()
) ?: return COMPILATION_ERROR
) ?: run {
configuration.perfManager?.notifyCompilerInitialized()
return COMPILATION_ERROR
}
environment.registerJavacIfNeeded(arguments).let {
if (!it) return COMPILATION_ERROR
}
Expand Down Expand Up @@ -249,16 +252,15 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
messageCollector: MessageCollector,
targetDescription: String
): KotlinCoreEnvironment? {
val perfManager = configuration.perfManager
perfManager?.targetDescription = targetDescription

if (messageCollector.hasErrors()) return null

val environment = KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)

val sourceFiles = environment.getSourceFiles()
configuration[CLIConfigurationKeys.PERF_MANAGER]?.apply {
this.targetDescription = targetDescription
addSourcesStats(sourceFiles.size, environment.countLinesOfCode(sourceFiles))
notifyCompilerInitialized()
}
perfManager?.addSourcesStats(sourceFiles.size, environment.countLinesOfCode(sourceFiles))

return if (messageCollector.hasErrors()) null else environment
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.jetbrains.kotlin.KtSourceFile
import org.jetbrains.kotlin.cli.common.*
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.DefaultDiagnosticReporter
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
Expand Down Expand Up @@ -63,7 +62,10 @@ object JvmFrontendPipelinePhase : PipelinePhase<ConfigurationPipelineArtifact, J
val (configuration, diagnosticsCollector, rootDisposable) = input
val messageCollector = configuration.messageCollector

val perfManager = configuration.perfManager

if (!checkNotSupportedPlugins(configuration, messageCollector)) {
perfManager?.notifyCompilerInitialized()
return null
}

Expand All @@ -74,7 +76,10 @@ object JvmFrontendPipelinePhase : PipelinePhase<ConfigurationPipelineArtifact, J
rootDisposable,
targetDescription,
diagnosticsCollector
) ?: return null
) ?: run {
perfManager?.notifyCompilerInitialized()
return null
}

FirAnalysisHandlerExtension.analyze(environment.project, configuration)?.let {
/*
Expand All @@ -89,15 +94,11 @@ object JvmFrontendPipelinePhase : PipelinePhase<ConfigurationPipelineArtifact, J
}
}

val performanceManager = configuration.perfManager
performanceManager?.apply {
this.targetDescription = targetDescription
notifyCompilerInitialized()
}

val sources = sourcesProvider()
val allSources = sources.allFiles

perfManager?.notifyCompilerInitialized()

if (
allSources.isEmpty() &&
!configuration.allowNoSourceFiles &&
Expand All @@ -109,7 +110,7 @@ object JvmFrontendPipelinePhase : PipelinePhase<ConfigurationPipelineArtifact, J
return null
}

performanceManager?.notifyAnalysisStarted()
perfManager?.notifyAnalysisStarted()
val sourceScope: AbstractProjectFileSearchScope
when (configuration.useLightTree) {
true -> {
Expand Down Expand Up @@ -164,7 +165,7 @@ object JvmFrontendPipelinePhase : PipelinePhase<ConfigurationPipelineArtifact, J
}
)

val countFilesAndLines = if (performanceManager == null) null else performanceManager::addSourcesStats
val countFilesAndLines = if (perfManager == null) null else perfManager::addSourcesStats
val outputs = sessionsWithSources.map { (session, sources) ->
val rawFirFiles = when (configuration.useLightTree) {
true -> session.buildFirViaLightTree(sources, diagnosticsCollector, countFilesAndLines)
Expand Down
1 change: 0 additions & 1 deletion compiler/testData/cli/jvm/reportPerfPsi.perf.log
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ Kotlin to JVM Compiler performance report
GC time for PS MarkSweep is $INT$ ms, $INT$ collections
GC time for PS Scavenge is $INT$ ms, $INT$ collections
INIT: Compiler initialized in $INT$ ms
INIT: Compiler initialized in $INT$ ms
JIT time is $INT$ ms
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Kotlin to JVM Compiler performance report
GC time for PS MarkSweep is $INT$ ms, $INT$ collections
GC time for PS Scavenge is $INT$ ms, $INT$ collections
INIT: Compiler initialized in $INT$ ms
JIT time is $INT$ ms

0 comments on commit 9fddcf0

Please sign in to comment.