Optimize Kotlin primary constructor fixture generation#1283
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR optimizes Kotlin primary constructor-based fixture generation without adding new dependencies or changing public APIs.
It reduces per-sample overhead in Kotlin object creation paths, which can become more visible when tests run under JVM instrumentation tools such as Kover.
(Optional): Description
The previous implementation always used
callBy(...)and built intermediate maps for every generated Kotlin object.callBy(...)is still necessary when optional constructor parameters should be omitted, but it is more expensive than needed when all parameters are already available.This PR keeps the existing optional-parameter behavior intact and only uses the faster
KFunction.call(*args)path when every constructor parameter can be provided.Changes include:
actualType()/cachedKotlin()calls inPrimaryConstructorArbitraryIntrospector.match().mapKeysallocation in the constructor invocation path by building the name-value map directly.KFunction.call(*args)when no optional constructor parameter needs to be skipped.callBy(...)when optional parameters must be skipped.nullbehavior for nullable optional parameters.List.containstoSet.contains.Local quick JMH benchmark:
Benchmark command:
./gradlew :fixture-monkey-benchmarks:fixture-monkey-benchmark-kotlin:jmh \ -Pjmh.quick \ '-Pjmh.include=.*primaryConstructorGenerateKotlinOrderSheetWithFixtureMonkey.*'How Has This Been Tested?
I also verified the benchmark above locally to compare the Kotlin primary constructor fixture generation path before and after this change.
Is the Document updated?
No.
This PR does not change public APIs, user-facing behavior, configuration, or documented usage. It only optimizes the existing Kotlin primary constructor generation path.
Please feel free to share any feedback, especially if there are concerns about the constructor invocation behavior or benchmark scope.