Decrease Light classes code generation in multithreaded cases by guarding KotlinClassInnerStuffCache, LightClassDataHolder.ForClass cache values calculation with lock

This commit is contained in:
Vladimir Dolzhenko
2019-09-13 15:10:09 +02:00
parent d3d85d50ab
commit c3265a8bf0
4 changed files with 110 additions and 38 deletions
@@ -43,7 +43,9 @@ sealed class LazyLightClassDataHolder(
cache.computeIfAbsent(lazyLightClassDataHolder, diagnostics)
}
private val exactResultLazyValue = lazyPub { builder(exactContextProvider()).stub }
private val _builderExactContextProvider: LightClassBuilderResult by lazyPub { builder(exactContextProvider()) }
private val exactResultLazyValue = lazyPub { _builderExactContextProvider.stub }
private val lazyInexactStub by lazyPub {
dummyContextProvider?.let { provider -> provider()?.let { context -> builder.invoke(context).stub } }
@@ -56,10 +58,9 @@ sealed class LazyLightClassDataHolder(
override val extraDiagnostics: Diagnostics
get() = diagnosticsHolderProvider().getOrCompute(this) {
builder(exactContextProvider()).diagnostics
// Force lazy diagnostics computation because otherwise a lot of memory is retained by computation.
// NB: Laziness here is not crucial anyway since somebody already has requested diagnostics and we hope one will use them
.takeUnless { it.isEmpty() } ?: Diagnostics.EMPTY
// Force lazy diagnostics computation because otherwise a lot of memory is retained by computation.
// NB: Laziness here is not crucial anyway since somebody already has requested diagnostics and we hope one will use them
_builderExactContextProvider.diagnostics.takeUnless { it.isEmpty() } ?: Diagnostics.EMPTY
}
// for facade or defaultImpls