Skip to content
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

Closed
jvandort opened this issue Aug 7, 2024 · 3 comments
Closed
Assignees
Labels
a:performance-improvement Performance improvement potential closed:duplicate Duplicated or superseeded by another issue has:release-notes-decision in:dependency-resolution engine metadata

Comments

@jvandort
Copy link
Member

jvandort commented Aug 7, 2024

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:

A marker interface for rules which can be safely reused because they are either
stateless, or effectively immutable. Ideally this should be inferred, which is
why the interface is internal.

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

@jvandort jvandort added a:feature A new functionality to-triage in:dependency-resolution engine metadata a:performance-improvement Performance improvement potential and removed a:feature A new functionality to-triage labels Aug 7, 2024
@jvandort jvandort added this to the 8.12 RC1 milestone Aug 7, 2024
@jvandort jvandort assigned jvandort and unassigned jvandort Aug 7, 2024
@jvandort jvandort added the 👋 team-triage Issues that need to be triaged by a specific team label Aug 7, 2024
@jvandort jvandort modified the milestones: 8.12 RC1, 8.11 RC1 Aug 7, 2024
@jvandort jvandort self-assigned this Aug 8, 2024
@jvandort jvandort removed the 👋 team-triage Issues that need to be triaged by a specific team label Aug 8, 2024
@jvandort
Copy link
Member Author

jvandort commented Aug 8, 2024

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.

@jvandort
Copy link
Member Author

We will be pursuing other performance enhancements that will solve this problem.

See #30199

@github-actions github-actions bot reopened this Aug 18, 2024
Copy link
Contributor

@jvandort This issue was closed as completed and looks release-note worthy, but no PR with release-notes update has been found.
Please, do one of the following:

  1. Attach a PR with the release notes update to this issue.
  2. Add the has:release-notes-decision label to the issue if it's not release-note-worthy or it was fixed in an old release and close the issue.
  3. Close issue as "not planned".

@github-actions github-actions bot added the pending:release-notes Indicates that the issue requires a release notes entry label Aug 18, 2024
@jvandort jvandort closed this as not planned Won't fix, can't repro, duplicate, stale Aug 19, 2024
@github-actions github-actions bot added to-triage and removed pending:release-notes Indicates that the issue requires a release notes entry labels Aug 19, 2024
@ov7a ov7a added closed:duplicate Duplicated or superseeded by another issue and removed to-triage labels Aug 20, 2024
@ov7a ov7a removed this from the 8.11 RC1 milestone Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:performance-improvement Performance improvement potential closed:duplicate Duplicated or superseeded by another issue has:release-notes-decision in:dependency-resolution engine metadata
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants