Skip to content

Commit cc379a8

Browse files
ivandev0Space Team
authored and
Space Team
committed
[CLI] Notify JS IR perf manager when generation is started and finished
#KT-67473 (cherry picked from commit f3cd3b1)
1 parent c3a1c4e commit cc379a8

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
9999
val messageCollector: MessageCollector,
100100
val mainCallArguments: List<String>?
101101
) {
102+
private val performanceManager = module.compilerConfiguration[CLIConfigurationKeys.PERF_MANAGER]
103+
102104
private fun lowerIr(): LoweredIr {
103105
return compile(
104106
module,
@@ -126,11 +128,18 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
126128
val transformer = IrModuleToJsTransformer(ir.context, mainCallArguments, ir.moduleFragmentToUniqueName)
127129

128130
val mode = TranslationMode.fromFlags(arguments.irDce, arguments.granularity, arguments.irMinimizedMemberNames)
129-
return transformer.makeJsCodeGenerator(ir.allModules, mode)
131+
return transformer
132+
.also { performanceManager?.notifyIRGenerationStarted() }
133+
.makeJsCodeGenerator(ir.allModules, mode)
130134
}
131135

132136
fun compileAndTransformIrNew(): CompilationOutputsBuilt {
133-
return makeJsCodeGenerator().generateJsCode(relativeRequirePath = true, outJsProgram = false)
137+
return makeJsCodeGenerator()
138+
.generateJsCode(relativeRequirePath = true, outJsProgram = false)
139+
.also {
140+
performanceManager?.notifyIRGenerationFinished()
141+
performanceManager?.notifyGenerationFinished()
142+
}
134143
}
135144
}
136145

Diff for: compiler/ir/backend.js/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44
}
55

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

Diff for: compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt

+8
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.invokeToplevel
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.collectNativeImplementations
@@ -49,6 +50,8 @@ fun compile(
4950
filesToLower: Set<String>? = null,
5051
granularity: JsGenerationGranularity = JsGenerationGranularity.WHOLE_PROGRAM,
5152
): LoweredIr {
53+
val performanceManager = depsDescriptors.compilerConfiguration[CLIConfigurationKeys.PERF_MANAGER]
54+
performanceManager?.notifyIRTranslationStarted()
5255

5356
val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer, moduleToName) =
5457
loadIr(depsDescriptors, irFactory, verifySignatures, filesToLower, loadFunctionInterfacesIntoStdlib = true)
@@ -92,6 +95,7 @@ fun compileIr(
9295
val moduleDescriptor = moduleFragment.descriptor
9396
val irFactory = symbolTable.irFactory
9497
val shouldGeneratePolyfills = configuration.getBoolean(JSConfigurationKeys.GENERATE_POLYFILLS)
98+
val performanceManager = configuration[CLIConfigurationKeys.PERF_MANAGER]
9599

96100
val allModules = when (mainModule) {
97101
is MainModule.SourceFiles -> dependencyModules + listOf(moduleFragment)
@@ -130,10 +134,14 @@ fun compileIr(
130134

131135
// TODO should be done incrementally
132136
generateJsTests(context, allModules.last())
137+
performanceManager?.notifyIRTranslationFinished()
133138

139+
performanceManager?.notifyGenerationStarted()
140+
performanceManager?.notifyIRLoweringStarted()
134141
(irFactory.stageController as? WholeWorldStageController)?.let {
135142
lowerPreservingTags(allModules, context, phaseConfig, it)
136143
} ?: jsPhases.invokeToplevel(phaseConfig, context, allModules)
137144

145+
performanceManager?.notifyIRLoweringFinished()
138146
return LoweredIr(context, moduleFragment, allModules, moduleToName)
139147
}

0 commit comments

Comments
 (0)