[ 
https://issues.apache.org/jira/browse/MNG-6575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16766534#comment-16766534
 ] 

Yann Dameron commented on MNG-6575:
-----------------------------------

Hi guys,

I'm new on Maven source code but make Dependency immutable looks like a massive 
change and like Robert I don't get how we can do that without impacting 
signatures, existing plugins, etc.

As I reported the memory issues, I tried to find a solution to evaluate the 
memory gain using wrappers.

I added a class which is responsible of caching all the Dependency objects

I created a DependencyWrapper class which extends Dependency and takes a 
Dependency object in the constructor (the original one, which comes from the 
cache).
This class overrides all methods. As long as modifiers are not called, all the 
getters redirect to the original dependency. 
As soon as a setter is called, original dependency is nullified and the 
DependencyWrapper class behaves like the Dependency one...

Finally, I modified the mdo to use this cache and wrappers.
 * BaseModel.setDependencies
 * DependencyManagement.setDependencies
 * ModelMerger.mergeModelBase_Dependencies
 * ModelMerger.mergeDependencyManagement_Dependencies

I know I missed some places, (for example if DependencyManagement.addDependency 
is called, the cache and wrappers will not be used) but it was a basic attempt 
to evaluate the memory gain and prevent API changes.

Doing that, the memory dump is reduced to 3.5Gb (8Gb with MNG-6571 fix, 12Gb 
with maven 3.6.0).

Do you think it's worth creating a patch for review and improvements ? I 
appreciate this approach could be a blocker so just let me know :)

> make Dependency immutable
> -------------------------
>
>                 Key: MNG-6575
>                 URL: https://issues.apache.org/jira/browse/MNG-6575
>             Project: Maven
>          Issue Type: Improvement
>          Components: Dependencies, Inheritance and Interpolation
>    Affects Versions: 3.6.0
>            Reporter: Hervé Boutemy
>            Priority: Major
>
> while working on Maven memory consumption issue MNG-6571, once VersionRange 
> is made immutable, memory used was divided by 2: the next big expected win is 
> to make Dependency immutable, which would probably once again divide memory 
> by 2 because the vast majority of time, dependencies (be it in 
> dependencyManagement or base dependencies) are inherited without any 
> modification
> this will require to change 
> [ModelMerger|https://maven.apache.org/ref/3.6.0/maven-model/apidocs/org/apache/maven/model/merge/ModelMerger.html]
>  's {{mergeDependency(Dependency target, Dependency source, boolean 
> sourceDominant, Map<Object,Object> context)}} signature, since is not really 
> an immutable friendly signature
> and also make [Dependency 
> code|https://maven.apache.org/ref/3.6.0/maven-model/apidocs/org/apache/maven/model/Dependency.html]
>  immutable (generated by Modello)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to