Skip to content

Conversation

@Squareys
Copy link
Contributor

Hii @dietzc !

I found out that PluginIndex re-adds all plugins of the PluginFinder everytime a new Context is created. This results in duplicates which are explicitly allowed by PluginIndex. Also, plugins are re-discovered every Context creation, which eliminates the performance gain we hoped for.

I believe this PR will solve that problem.

Greetings,
Jonathan

Allows us to reuse a PluginIndex for multiple contexts.

Signed-off-by: Squareys <Squareys@googlemail.com>
Signed-off-by: Squareys <Squareys@googlemail.com>
Not very useful otherwise.

Signed-off-by: Squareys <Squareys@googlemail.com>
@dietzc
Copy link
Member

dietzc commented Oct 12, 2015

is this potentially also a bug on SciJava side @ctrueden?

Thanks @Squareys

dietzc added a commit that referenced this pull request Oct 12, 2015
@dietzc dietzc merged commit e5fa4d1 into rc_0.2.0 Oct 12, 2015
@dietzc dietzc deleted the reuse-plugin-index branch October 12, 2015 11:22
@ctrueden
Copy link
Member

Yeah, I suppose you could call it an unintuitive quirk of when plugin discovery happens. Looking at it now, I think it would probably make more sense to discover all the plugins immediately upon creation of the PluginIndex, and get rid of the public discover() method. We could change this for SJC3; see scijava/scijava-common#196.

In the meantime, there is another workaround which shouldn't require you to create a new subclass:

PluginIndex pluginIndex = new PluginIndex(null);
ArrayList<PluginInfo<?>> plugins = new ArrayList<>();
pluginFinder.findPlugins(plugins);
pluginIndex.addAll(plugins);

That is: passing null to the PluginIndex ensures no PluginFinder is linked to it, so every time you create a new Context with it, its discover() method will do nothing.

I didn't test this, but in theory it should work.

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.

4 participants