apache / apache/maven-enforcer

Rule speedup through dependency resolution caching

Open
#934 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
161
Forks
180
Avg merge
1d 20m
Merged PRs (30d)
8

Description

### New feature, improvement proposal

We have a large multi-module build with quite a number of built-in and [extra](https://github.com/mojohaus/extra-enforcer-rules) enforcer rules enabled. For modules with many dependencies, plugin execution takes several seconds, adding up to hundreds of seconds over-all. Based on some profiling, most time is spent repeatedly collecting dependency information:

Image

I had a brief look at the code, and besides [full rule caching](https://github.com/apache/maven-enforcer/blob/ee5abeeabba6acad11b3b5ba279def0ab6c1f80c/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/internal/EnforcerRuleCache.java#L57) it appears that dependency resolution isn't cached. Would it be possible to add this, such that distinct rules applied to the same module can reuse invariant dependency information?

---

I suppose that the changes in #930 could be extended to support more fine-grained caching ([`AbstractResolveDependencies#collectProjectDependencies()`](https://github.com/mojohaus/extra-enforcer-rules/blob/1faa3fec2f557c289339c6dd78ff945355a74e7d/src/main/java/org/codehaus/mojo/extraenforcer/dependencies/AbstractResolveDependencies.java#L92) would be an easy candidate), but [`SessionData`](https://maven.apache.org/resolver/apidocs/org/eclipse/aether/SessionData.html)'s documentation explicitly states:
> Unlike a cache, this session data is not subject to purging. For this same reason, session data should also not be abused as a cache (i.e. for storing values that can be re-calculated) to avoid memory exhaustion.

There's also [`EnforcerRuleHelper#getCache(String key, Supplier producer)`](https://github.com/apache/maven-enforcer/blob/ee5abeeabba6acad11b3b5ba279def0ab6c1f80c/enforcer-api/src/main/java/org/apache/maven/enforcer/rule/api/EnforcerRuleHelper.java#L126), but `EnforcerRuleHelper` is deprecated.

I can't promise to have time in the near feature to help implement any improvement in this area, but if one were to attempt this, what would be the recommended approach?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the referenced EnforcerRuleCache implementation and the changes in #930, then compare the dependency collection flow in AbstractResolveDependencies#collectProjectDependencies(). Review SessionData and the deprecated EnforcerRuleHelper#getCache API before choosing an approach. Done means distinct rules can reuse invariant dependency information without unbounded session memory growth.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.