Skip to content

refine getPluginsAsMap #2482

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

XenoAmess
Copy link
Contributor

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.

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


volatile Map<String, Plugin> pluginMap;

protected void cleanDelegateCache() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this? Why not just call flushPluginMap? It's only a one-liner

Copy link
Contributor Author

@XenoAmess XenoAmess Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it is weird to register flushPluginMap as a function in the base class.
the idea was, cleanDelegateCache be a abstract class, and the flushPluginMap is only what this specific situation in this class needs.
well, we decide to continue using modello, didn't we.....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe inline flushPluginMap into this method?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather avoid any breakage in the 3.x model since it's supposed to be stable.

* @see Plugin#getKey()
*/
public Map<String, Plugin> getPluginsAsMap() {
return getPlugins().stream().collect(Collectors.toMap(plugin -> plugin.getKey(), plugin -> plugin));
if (pluginMap == null) {
synchronized (this) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a specific problem but the thread safety here makes me nervous.

@XenoAmess
Copy link
Contributor Author

XenoAmess commented Jun 18, 2025

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...

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?


volatile Map<String, Plugin> pluginMap;

protected void cleanDelegateCache() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe inline flushPluginMap into this method?

@XenoAmess
Copy link
Contributor Author

XenoAmess commented Jun 19, 2025

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.

}

/**
* @return a Map of plugins field with {@code Plugins#getKey()} as key
* @return a Map of plugins field with {@link Plugin#getKey()} as key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a map of plugin keys to plugins

@elharo
Copy link
Contributor

elharo commented Jun 20, 2025

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.


volatile Map<String, Plugin> pluginMap;

protected void cleanDelegateCache() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs Override annotation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants