[JS IR] IC invalidation performance improvements

- Cache signature readers and deserializers
 - Cache inline function hashes
 - IC refactoring
 - [gradle] Use hash of module path for cache dir; Fix KT-51238

^KT-51238 Fixed
This commit is contained in:
Alexander Korepanov
2022-02-10 12:23:24 +03:00
committed by Space
parent 290a06676d
commit 43a0876c26
22 changed files with 315 additions and 257 deletions
@@ -26,9 +26,12 @@ import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode.DEVELOPMENT
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode.PRODUCTION
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
import org.jetbrains.kotlin.gradle.utils.getValue
import org.jetbrains.kotlin.gradle.utils.toHexString
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
import java.io.File
import java.nio.charset.StandardCharsets
import java.security.MessageDigest
import javax.inject.Inject
@CacheableTask
@@ -65,10 +68,6 @@ abstract class KotlinJsIrLink @Inject constructor(
@get:Internal
internal val propertiesProvider = PropertiesProvider(project)
@get:Inject
open val fileHasher: FileHasher
get() = throw UnsupportedOperationException()
@get:Input
internal val incrementalJsIr: Boolean = propertiesProvider.incrementalJsIr
@@ -125,15 +124,17 @@ abstract class KotlinJsIrLink @Inject constructor(
)
}
if (incrementalJsIr && mode == DEVELOPMENT) {
val digest = MessageDigest.getInstance("SHA-256")
args.cacheDirectories = args.libraries?.splitByPathSeparator()
?.map {
val file = File(it)
val hash = digest.digest(file.normalize().absolutePath.toByteArray(StandardCharsets.UTF_8)).toHexString()
rootCacheDirectory
.resolve(file.nameWithoutExtension)
.resolve(hash)
.also {
it.mkdirs()
}
.resolve(fileHasher.hash(file).toString())
}
?.plus(rootCacheDirectory.resolve(entryModule.get().asFile.name))
?.let {
@@ -43,7 +43,7 @@ fun getCacheDirectory(
return File(cacheDirectory, computeDependenciesHash(dependency))
}
private fun ByteArray.toHexString() = joinToString("") { (0xFF and it.toInt()).toString(16).padStart(2, '0') }
internal fun ByteArray.toHexString() = joinToString("") { (0xFF and it.toInt()).toString(16).padStart(2, '0') }
private fun computeDependenciesHash(dependency: ResolvedDependency): String {
val allArtifactsPaths =
@@ -103,4 +103,4 @@ internal class GradleLoggerAdapter(private val gradleLogger: Logger) : org.jetbr
override fun warning(message: String) = gradleLogger.warn(message)
override fun error(message: String) = kotlin.error(message)
override fun fatal(message: String): Nothing = kotlin.error(message)
}
}