Skip to content

Commit bd64553

Browse files
committed
SearchService: improve enabled lookup performance
I didn't benchmark it, but this should be much faster for two reasons: 1. We only ask the PluginService for the Searcher's PluginInfo when an already-persisted value is not found in the PrefService. 2. We use the getPlugin(Class pluginClass, Class pluginType) method, which is more performant because it needs to dig through only the list of plugins of the given type. Previously, we were using getPlugin(Class pluginClass) which needed to dig through every PluginInfo on every request.
1 parent b85c969 commit bd64553

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/main/java/org/scijava/search/DefaultSearchService.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.scijava.plugin.AbstractSingletonService;
3333
import org.scijava.plugin.Parameter;
3434
import org.scijava.plugin.Plugin;
35+
import org.scijava.plugin.PluginInfo;
3536
import org.scijava.prefs.PrefService;
3637
import org.scijava.service.Service;
3738

@@ -50,9 +51,12 @@ public class DefaultSearchService extends
5051

5152
@Override
5253
public boolean enabled(final Searcher s) {
53-
final boolean defaultValue = //
54-
pluginService().getPlugin(s.getClass()).isEnabled();
55-
return prefService.getBoolean(s.getClass(), "enabled", defaultValue);
54+
final String enabled = prefService.get(s.getClass(), "enabled");
55+
if (enabled != null) return Boolean.valueOf(enabled);
56+
// Get the default value from enabled property of PluginInfo.
57+
final PluginInfo<Searcher> info = //
58+
pluginService().getPlugin(s.getClass(), Searcher.class);
59+
return info == null ? false : info.isEnabled();
5660
}
5761

5862
@Override

0 commit comments

Comments
 (0)