Skip to content

Commit f3cd3b1

Browse files
ivandev0Space Team
authored andcommitted
[CLI] Notify JS IR perf manager when generation is started and finished
#KT-67473
1 parent 0867bf1 commit f3cd3b1

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
111111
val messageCollector: MessageCollector,
112112
val mainCallArguments: List<String>?
113113
) {
114+
private val performanceManager = module.compilerConfiguration[CLIConfigurationKeys.PERF_MANAGER]
115+
114116
private fun lowerIr(): LoweredIr {
115117
return compile(
116118
mainCallArguments,
@@ -139,11 +141,18 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
139141
val transformer = IrModuleToJsTransformer(ir.context, ir.moduleFragmentToUniqueName, mainCallArguments != null)
140142

141143
val mode = TranslationMode.fromFlags(arguments.irDce, arguments.granularity, arguments.irMinimizedMemberNames)
142-
return transformer.makeJsCodeGenerator(ir.allModules, mode)
144+
return transformer
145+
.also { performanceManager?.notifyIRGenerationStarted() }
146+
.makeJsCodeGenerator(ir.allModules, mode)
143147
}
144148

145149
fun compileAndTransformIrNew(): CompilationOutputsBuilt {
146-
return makeJsCodeGenerator().generateJsCode(relativeRequirePath = true, outJsProgram = false)
150+
return makeJsCodeGenerator()
151+
.generateJsCode(relativeRequirePath = true, outJsProgram = false)
152+
.also {
153+
performanceManager?.notifyIRGenerationFinished()
154+
performanceManager?.notifyGenerationFinished()
155+
}
147156
}
148157
}
149158

compiler/ir/backend.js/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44
}
55

66
dependencies {
7+
api(project(":compiler:cli-base"))
78
api(project(":compiler:util"))
89
api(project(":compiler:frontend"))
910
api(project(":compiler:backend-common"))

compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.ir.backend.js
88
import org.jetbrains.kotlin.backend.common.linkage.issues.checkNoUnboundSymbols
99
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
1010
import org.jetbrains.kotlin.backend.common.phaser.PhaserState
11+
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
1112
import org.jetbrains.kotlin.config.CompilerConfiguration
1213
import org.jetbrains.kotlin.ir.IrBuiltIns
1314
import org.jetbrains.kotlin.ir.backend.js.lower.*
@@ -48,6 +49,8 @@ fun compile(
4849
filesToLower: Set<String>? = null,
4950
granularity: JsGenerationGranularity = JsGenerationGranularity.WHOLE_PROGRAM,
5051
): LoweredIr {
52+
val performanceManager = depsDescriptors.compilerConfiguration[CLIConfigurationKeys.PERF_MANAGER]
53+
performanceManager?.notifyIRTranslationStarted()
5154

5255
val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer, moduleToName) =
5356
loadIr(depsDescriptors, irFactory, verifySignatures, filesToLower, loadFunctionInterfacesIntoStdlib = true)
@@ -93,6 +96,7 @@ fun compileIr(
9396
val moduleDescriptor = moduleFragment.descriptor
9497
val irFactory = symbolTable.irFactory
9598
val shouldGeneratePolyfills = configuration.getBoolean(JSConfigurationKeys.GENERATE_POLYFILLS)
99+
val performanceManager = configuration[CLIConfigurationKeys.PERF_MANAGER]
96100

97101
val allModules = when (mainModule) {
98102
is MainModule.SourceFiles -> dependencyModules + listOf(moduleFragment)
@@ -132,7 +136,10 @@ fun compileIr(
132136

133137
// TODO should be done incrementally
134138
generateJsTests(context, allModules.last(), groupByPackage = false)
139+
performanceManager?.notifyIRTranslationFinished()
135140

141+
performanceManager?.notifyGenerationStarted()
142+
performanceManager?.notifyIRLoweringStarted()
136143
(irFactory.stageController as? WholeWorldStageController)?.let {
137144
lowerPreservingTags(allModules, context, phaseConfig, it)
138145
} ?: run {
@@ -143,6 +150,7 @@ fun compileIr(
143150
}
144151
}
145152
}
153+
performanceManager?.notifyIRLoweringFinished()
146154

147155
return LoweredIr(context, moduleFragment, allModules, moduleToName)
148156
}

0 commit comments

Comments
 (0)