[Performance Enhancements] Lambda expressions format change & Multi-level exploration logic changes#1535
[Performance Enhancements] Lambda expressions format change & Multi-level exploration logic changes#1535bulldozer-bot[bot] merged 14 commits intodevelopfrom
Conversation
Generate changelog in
|
Invalidated by push of b3de33c
|
👍 |
[skip ci]
8f76341 to
8761f21
Compare
|
👍 |
relative symlink? comment sptless comments
LAST_LEVELS_TO_EXPLORE levels
|
👍 |
[skip ci]
right comment comment
[skip ci]
Invalidated by push of de3b8eb
LAST_LEVELS_TO_EXPLORE levels
✅ Successfully generated changelog entry!Need to regenerate?Simply interact with the changelog bot comment again to regenerate these entries. 📋Changelog Preview💡 Improvements
|
|
👍 |
|
Released 2.89.0 |
|
Good evening, please let me know if it's better to open an issue. I would like to ask whether the following type of formatting changes introduced in 2.89.0 is fully intentional: - testing.getSuites().named(INTEGRATION_TEST_SUITE_NAME, JvmTestSuite.class, suite -> MainSourceSet.of(project)
- .addAsCompileOnlyApiDependency(suite));
+ testing.getSuites()
+ .named(
+ INTEGRATION_TEST_SUITE_NAME,
+ JvmTestSuite.class,
+ suite -> MainSourceSet.of(project).addAsCompileOnlyApiDependency(suite));The old way was quite peculiar, but the new one is too eager to introduce line breaks and extra nesting, even when the lines are relatively short. Extracting code into temporary variables seems to be the only way to avoid the extra nesting, e.g.: + final var testingSuites = testing.getSuites();
+
- testing.getSuites().named(INTEGRATION_TEST_SUITE_NAME, JvmTestSuite.class, suite -> MainSourceSet.of(project)
- .addAsCompileOnlyApiDependency(suite));
+ testingSuites.named(
+ INTEGRATION_TEST_SUITE_NAME,
+ JvmTestSuite.class,
+ suite -> MainSourceSet.of(project).addAsCompileOnlyApiDependency(suite)); |
Before this PR
Some repos would take 5 - 9 mins to be formatted. This is because we were exploring both
preferBreakingLastInnerLevel&breakNormallyfor each level, with the branching coefficient capped to 20. The exploration is exponential. See below the Benchmark for the before implementation:After this PR
Performance dashboards here. Internal excavator runs here
Example of the new diff: here or here
Most of the times we prefer
preferBreakingLastInnerLevelin order to keep as compact as possible. I changed the logic that started the exploration top-down (with a branching coefficient capped at 20) to an exploration of the lastLAST_LEVELS_TO_EXPLORElevels. For the lastLAST_LEVELS_TO_EXPLOREI am exploring bothpreferBreakingLastInnerLevel&breakNormallyand I will pick the formatted text that minimises the number of lines.In order to keep the formatting as compact as possible, I am defaulting to
preferBreakingLastInnerLevelfor all the upper levels. If no such formatting was found, then I am falling back tobreakNormally.with
LAST_LEVELS_TO_EXPLORE=8Because the number of exploration is substantially decreased, just changing the above setup would end up in some cases looking like here. I've noticed that most of the time the setup was wrong was for lambda expressions.
I changed the logic for lambda expressions (lambda body with no curly braces), to instead of trying to inline as much as possible the inner levels of the lambda body (code here) to defaulting to
breakNormally:lambda expressionfits completely on the same line as the parent, it will be inlinedlambda bodygets split in multiple lines.Other things that I tried:
LAST_LEVELS_TO_EXPLORE = 12, noticed some perf regression for some repos.==COMMIT_MSG==
Improve perf by inspecting both breaking & not-breaking for the
LAST_LEVELS_TO_EXPLORElevels==COMMIT_MSG==
LAST_LEVELS_TO_EXPLORE = 7, however the formatting would regress in some cases (internal link here). Setting level = 12 fixed the issue.fj.Setto using a normalHashSet, however this ended up being (more than 10x) slower. This is because the State is immutable and every time we create a new State, we need to copy & edit eachSetfield, which is much more optimal to do with thefjlibrary than using a normalHashSet.See image below from the jfr.
Possible downsides?