-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically cache CompatibilityRule and DisambiguationRule instances #30110
Comments
We have decided to automatically cache these rules across the board. It is a slight behavior change if these rules previously had mutable state or side-effects in their constructor, but we determined this would be a rare scenario, and is behavior we would want to avoid. Further, automatic detection of mutability (via reflection) is complex, and not worth it if we expect all rules to be immutable and deterministic anyway. We will announce this change in the upgrade guide as a potential breaking change. AGP and KGP rules are verified to be stateless and/or immutable with deterministic constructors. Spring boot plugin does not define any rules. |
We will be pursuing other performance enhancements that will solve this problem. See #30199 |
@jvandort This issue was closed as completed and looks release-note worthy, but no PR with release-notes update has been found.
|
Expected Behavior
Instantiating compatibility and disambiguation rules do not affect performance. This is particularly apparent for
CompatibilityRuleChain
, which is called much more often and in loops.Current Behavior (optional)
The instantiation of these rules affects performance, as this code is visible in flamegraphs.
Context
In InstantiatingAction.java, we cache instantiated compatibility and disambiguation rule instances only if it is marked with
ReuableAction
. That interface has the following javadoc:Note, this is only apparent for non-java projects, as all of Gradle's rules are marked with
ReusableAction
.Attached are two flamegraphs which display the performance hit.
android-extra-large-benchmark, 2000 projects:
androidStudioSync-8 10-20240723143313+0000-cpu-simplified-flames
JFR snapshots from the Block build:
#29026 (comment)
https://gradle.slack.com/archives/CMBB2G345/p1722970341730999?thread_ts=1721163778.318379&cid=CMBB2G345
The text was updated successfully, but these errors were encountered: