Initialize the RuleClassProvider only once.
This saves some CPU/wall time when creating multiple PackageLoader instances.
RELNOTES: None
@@ -16,6 +16,7 @@ package com.google.devtools.build.lib.skyframe.packages;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
import com.google.devtools.build.lib.bazel.rules.BazelRuleClassProvider;
import com.google.devtools.build.lib.packages.BuildFileName;
import com.google.devtools.build.lib.packages.PackageFactory.EnvironmentExtension;
@@ -76,6 +77,9 @@ public class BazelPackageLoader extends AbstractPackageLoader {
/** Builder for {@link BazelPackageLoader} instances. */
public static class Builder extends AbstractPackageLoader.Builder {
+ private static final ConfiguredRuleClassProvider DEFAULT_RULE_CLASS_PROVIDER =
+ BazelRuleClassProvider.create();
+
private Builder(Path workspaceDir) {
super(workspaceDir);
}
@@ -87,12 +91,12 @@ public class BazelPackageLoader extends AbstractPackageLoader {
@Override
protected RuleClassProvider getDefaultRuleClassProvider() {
- return BazelRuleClassProvider.create();
+ return DEFAULT_RULE_CLASS_PROVIDER;
}
@Override
protected String getDefaultDefaultPackageContents() {
- return BazelRuleClassProvider.create().getDefaultsPackageContent(
+ return DEFAULT_RULE_CLASS_PROVIDER.getDefaultsPackageContent(
InvocationPolicy.getDefaultInstance());
}
}
