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.
What's changed?
RecipeSpec
methodsrecipeFromYaml
,recipeFromResource
, andrecipeFromResources
now memoize Recipes to avoid repeated redundant Environment instantiation / classpath scanningWhat's your motivation?
Speed of unit tests; these methods (especially when calling
scanYamlResources
) can cost a few hundred milliseconds, which adds up fast if a large test class is using them.Have you considered any alternatives or workarounds?
Environment
built with thescanYamlResources
call in a lazy-init static field; this probably delivers ~most of the speed benefits with less code and less memtestClassSpec
objects used byrewriteRun
, but that was impractical sinceRewriteTest
is an interface and can't support instance variablesWeakHashMap<Consumer<RecipeSpec>, RecipeSpec>
to cachetestClassSpec
objects based on the customizer (egthis::defaults
) which would produce them, but I couldn't get keys with consistent memory references. And even if I could figure out clever lambda syntax to make that happen, it would depend on the test class being configured to asTestInstanceLifecycle(PER_CLASS)
, which is non-default and has other ramificationsAny additional context
Checklist
./gradlew licenseFormat