maven icon indicating copy to clipboard operation
maven copied to clipboard

refine getPluginsAsMap

Open XenoAmess opened this issue 6 months ago • 3 comments

Following this checklist to help us incorporate your contribution quickly and easily:

  • [ ] Your pull request should address just one issue, without pulling in other changes.
  • [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • [ ] Each commit in the pull request should have a meaningful subject line and body. Note that commits might be squashed by a maintainer on merge.
  • [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible but is a best-practice.
  • [ ] Run mvn verify to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • [ ] You have run the Core IT successfully.

If your pull request is about ~20 lines of code you don't need to sign an Individual Contributor License Agreement if you are unsure please ask on the developers list.

To make clear that you license your contribution under the Apache License Version 2.0, January 2004 you have to acknowledge this by using the following check-box.

XenoAmess avatar Jun 14 '25 06:06 XenoAmess

I don't really follow the purpose of this PR. maybe someone else will.

@elharo for not constructing the map in getPluginsAsMap every time. getting a plugin from a map is just a O(1) (if we use hashmap based maps here) but the current impl nees a O(n) full map building. and the most cases when we invoke this function, we just want to use it with : 'getPluginsAsMap().get(key)', which is costing when the pluginMap is really big.

Though the bitter truth is adding the prs I opened last weekend in maven project up, has about 3% performance increasing on that test on my machine, but the maven-resolver pr I opened has 30%+ performance refnie. bottleneck is not on maven, but resolver...

XenoAmess avatar Jun 18 '25 13:06 XenoAmess

Instead of building a map, lazily or not, could we instead only have a map and iterate through that instead of a list of plugins?

Yes that is thr original thought. Though I have no idea how to make modello generate it to a map, not a list A LinkedHashMap can solve anything in this case. though modello...well, I have even no idea now to make a new grammar to tell the generator to generate this field as a LinkedHashMap, using which param as key... I don't really familiar with modello...though maybe I can have a try when have time.

XenoAmess avatar Jun 19 '25 12:06 XenoAmess

Modello isn't very well documented or supported. If you make the plugins field a map instead of a list, it might work, but it might not. I'm not sure. There might be some way to add custom code and replace default generated code with custom code, but again I don't really know.

elharo avatar Jun 20 '25 10:06 elharo

Modello is nowadays only used as the input, we don't use it to generate code directly anymore. I made some performance measurements, and this patch actually does not work. The reason is that the org.apache.maven.model objects that wraps the immutable ones are often recreated, so caching the plugins map inside those does not help.

gnodet avatar Jun 30 '25 04:06 gnodet

Modello is nowadays only used as the input, we don't use it to generate code directly anymore. I made some performance measurements, and this patch actually does not work. The reason is that the org.apache.maven.model objects that wraps the immutable ones are often recreated, so caching the plugins map inside those does not help.

seems we shall solver the recreation first. btw I'm trying to make it use the other way, that make it use linkedHashMap instead of a list in this structure...

XenoAmess avatar Jun 30 '25 04:06 XenoAmess

Modello is nowadays only used as the input, we don't use it to generate code directly anymore. I made some performance measurements, and this patch actually does not work. The reason is that the org.apache.maven.model objects that wraps the immutable ones are often recreated, so caching the plugins map inside those does not help.

seems we shall solver the recreation first. btw I'm trying to make it use the other way, that make it use linkedHashMap instead of a list in this structure...

I'm experimenting with the following patch instead:

   public Plugin getPlugin(String pluginKey) {
        var plugin = getBuild().getDelegate().getPluginsAsMap().get(pluginKey);
        return plugin != null ? new Plugin(plugin) : null;
    }

gnodet avatar Jun 30 '25 05:06 gnodet

Modello is nowadays only used as the input, we don't use it to generate code directly anymore. I made some performance measurements, and this patch actually does not work. The reason is that the org.apache.maven.model objects that wraps the immutable ones are often recreated, so caching the plugins map inside those does not help.

seems we shall solver the recreation first. btw I'm trying to make it use the other way, that make it use linkedHashMap instead of a list in this structure...

I'm experimenting with the following patch instead:

   public Plugin getPlugin(String pluginKey) {
        var plugin = getBuild().getDelegate().getPluginsAsMap().get(pluginKey);
        return plugin != null ? new Plugin(plugin) : null;
    }

I've raised https://github.com/apache/maven/pull/2530

gnodet avatar Jun 30 '25 05:06 gnodet

Superseded with #2530

gnodet avatar Jun 30 '25 18:06 gnodet