elihart
11/01/2021, 9:29 PMyigit
11/01/2021, 9:31 PMyigit
11/01/2021, 9:32 PMyigit
11/01/2021, 9:33 PMelihart
11/01/2021, 9:40 PM./gradlew module:clean module:assembleDebug --no-build-cache
even with stub generation taken into account ksp is twice as slow. but I believe KSP claimed that even without stub generation KSP should be faster because they can do more granular type resolution on demandyigit
11/01/2021, 9:42 PMyigit
11/01/2021, 9:44 PMyigit
11/01/2021, 9:45 PMelihart
11/01/2021, 9:46 PMyigit
11/01/2021, 10:06 PMyigit
11/01/2021, 10:06 PMyigit
11/01/2021, 10:11 PMtotals:
kapt : 53759 ms
ksp : 33144 ms
taskTotals:
kaptWithKaptDebugAndroidTestKotlin : 22754 ms
kaptClasspath_kaptWithKaptDebugKotlin : 0 ms
kaptClasspath_kaptDebugKotlin : 1 ms
kspWithKspDebugAndroidTestKotlin : 32804 ms
kaptAndroidTestWithKapt : 329 ms
kaptGenerateStubsWithKaptDebugAndroidTestKotlin : 30438 ms
kaptAndroidTestDebug : 0 ms
kapt : 1 ms
kaptAndroidTest : 0 ms
kspAndroidTestWithKsp : 319 ms
kaptGenerateStubsWithKaptDebugKotlin : 80 ms
kaptWithKaptDebugKotlin : 41 ms
kaptGenerateStubsDebugKotlin : 50 ms
kspWithKspDebugAndroidTestKotlinProcessorClasspath : 21 ms
kaptDebugKotlin : 37 ms
kaptWithKapt : 0 ms
kaptDebug : 0 ms
kaptWithKaptDebug : 0 ms
kaptAndroidTestWithKaptDebug : 0 ms
kaptClasspath_kaptWithKaptDebugAndroidTestKotlin : 28 ms
`
elihart
11/01/2021, 10:25 PMelihart
11/02/2021, 12:52 AMgetDeclaredMethods
takes a significant amount of time, in large part I think because of forces type resolution for this
// if it receives or returns inline, drop it.
// we can re-enable these once room generates kotlin code
it.parameters.any {
it.type.resolve().isInline()
} || it.returnType?.resolve()?.isInline() == true
similarly syntheticGetterSetterMethods
checks type for inline functions. I suppose anywhere that xprocessing currently resolves type should try to be deferred as much as possible.
that’s really wasteful for my specific use case. I’m not sure how flexible you want to make the xprocessing api’s - it might be easier to have an escape hatch to expose the ksp resolver so we can do efficient things when we know we’re in ksp (right now I access the resolver reflectively, but it would be nice to have a real api)
similarly maybe access to modifiers should be deferred more. for example, getting all methods forces creation of modifiers, when we could probably defer knowing whether its a suspend function
return if (declaration.modifiers.contains(Modifier.SUSPEND)) {
KspSuspendMethodElement(env, containing, declaration)
} else {
KspNormalMethodElement(env, containing, declaration)
}
Also, accessing rawType seems to not defer creation of type name
constructor(original: KspType) : this(
ksType = original.ksType.starProjection().makeNotNullable(),
typeName = original.typeName.rawTypeName()
)
and that is a big chunk of my flame graph
I think addressing those two things should help me a lot actuallyelihart
11/02/2021, 1:05 AMgetSymbolsWithAnnotation -> resolveToUnderlying
which I suppose is to be expected, but would be great if some optimizations could be done eventuallyJiaxiang
11/02/2021, 3:22 AMgetSymbolsWithAnnotation
, the overhead comes from resolving annotation type, we do have some optimizations in place before calling resolveToUnderlying
, we will look into if we can put more optimization, but my guess is it is most likely marginal since a type resolution is unavoidable, unless we can improve performance for type resolution.elihart
11/02/2021, 5:15 AMTing-Yuan Huang
11/02/2021, 8:17 AMyigit
11/02/2021, 2:56 PMelihart
11/02/2021, 5:54 PMdoes your code never need those resolutions?yes, in many cases we either only need names, or are filtering the methods/fields so it is wasteful to resolve all of them
elihart
11/02/2021, 5:54 PMyigit
11/02/2021, 6:45 PMyigit
11/03/2021, 3:56 PMyigit
11/03/2021, 3:56 PMelihart
11/03/2021, 4:56 PMgradle-profiler --profile jprofiler --jprofiler-config sampling-all --scenario-file profiling.scenarios
With a profiling.scenarios
file like
default-scenarios = ["profiling"]
profiling {
title = "Profile ksp"
tasks = ["kspDebugKotlin"]
cleanup-tasks = ["clean"]
gradle-args = ["--no-build-cache", "-Dkotlin.compiler.execution.strategy=in-process"]
daemon = none
}
elihart
11/03/2021, 4:56 PMyigit
11/03/2021, 5:26 PMyigit
11/03/2021, 5:32 PMyigit
11/03/2021, 5:33 PMyigit
11/03/2021, 6:45 PMyigit
11/03/2021, 6:48 PMelihart
11/03/2021, 6:52 PMyigit
11/03/2021, 10:39 PMelihart
11/04/2021, 12:03 AM