diff options
author | tomlu <tomlu@google.com> | 2017-08-11 21:32:01 +0200 |
---|---|---|
committer | Irina Iancu <elenairina@google.com> | 2017-08-14 14:15:38 +0200 |
commit | 8306d437ab758c8a45468c77635417a586eecad7 (patch) | |
tree | 84711af35d65c16ac05062fbbb1da9b617358bcb /src/main/java/com/google | |
parent | 50f72495a5a1bfbb4ef57a42a81872b42829fb9f (diff) |
Intern aspect definitions by their respective aspect class + parameters.
RELNOTES: None
PiperOrigin-RevId: 165010750
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/packages/Aspect.java | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Aspect.java b/src/main/java/com/google/devtools/build/lib/packages/Aspect.java index 817bc3c69c..3ef497697b 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Aspect.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Aspect.java @@ -15,6 +15,8 @@ package com.google.devtools.build.lib.packages; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.util.Preconditions; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * An instance of a given {@code AspectClass} with loaded definition and parameters. @@ -30,6 +32,17 @@ public final class Aspect implements DependencyFilter.AttributeInfoProvider { /** */ public static final String INJECTING_RULE_KIND_PARAMETER_KEY = "$injecting_rule_kind"; + /** + * The aspect definition is a function of the aspect class + its parameters, so we can cache that. + * + * <p>The native aspects are loaded with blaze and are not stateful. Reference equality works fine + * in this case. + * + * <p>Caching of Skylark aspects is not yet implemented. + */ + private static final Map<NativeAspectClass, Map<AspectParameters, AspectDefinition>> + definitionCache = new ConcurrentHashMap<>(); + private final AspectDescriptor aspectDescriptor; private final AspectDefinition aspectDefinition; @@ -45,7 +58,11 @@ public final class Aspect implements DependencyFilter.AttributeInfoProvider { public static Aspect forNative( NativeAspectClass nativeAspectClass, AspectParameters parameters) { - return new Aspect(nativeAspectClass, nativeAspectClass.getDefinition(parameters), parameters); + AspectDefinition definition = + definitionCache + .computeIfAbsent(nativeAspectClass, key -> new ConcurrentHashMap<>()) + .computeIfAbsent(parameters, nativeAspectClass::getDefinition); + return new Aspect(nativeAspectClass, definition, parameters); } public static Aspect forNative(NativeAspectClass nativeAspectClass) { @@ -54,9 +71,9 @@ public final class Aspect implements DependencyFilter.AttributeInfoProvider { public static Aspect forSkylark( SkylarkAspectClass skylarkAspectClass, - AspectDefinition definition, + AspectDefinition aspectDefinition, AspectParameters parameters) { - return new Aspect(skylarkAspectClass, definition, parameters); + return new Aspect(skylarkAspectClass, aspectDefinition, parameters); } /** |