aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Janak Ramakrishnan <janakr@google.com>2015-11-05 14:59:45 +0000
committerGravatar John Field <jfield@google.com>2015-11-05 16:52:08 +0000
commit21609586ff4dc30b800c7801c15aedde1f0ec2cf (patch)
tree388afa5b7a4484f4412fa41dd48ade587134e95b /src
parenta58dcd1d9db64032c2f4c25cb6d14225bc34f065 (diff)
Intern rdep removal operations to save memory on incremental builds.
-- MOS_MIGRATED_REVID=107135644
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/skyframe/ReverseDepsUtil.java34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/skyframe/ReverseDepsUtil.java b/src/main/java/com/google/devtools/build/skyframe/ReverseDepsUtil.java
index d0f6d4ac82..86c39ab2e5 100644
--- a/src/main/java/com/google/devtools/build/skyframe/ReverseDepsUtil.java
+++ b/src/main/java/com/google/devtools/build/skyframe/ReverseDepsUtil.java
@@ -17,6 +17,8 @@ import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Interner;
+import com.google.common.collect.Interners;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.devtools.build.lib.collect.CompactHashSet;
@@ -46,6 +48,8 @@ public abstract class ReverseDepsUtil<T> {
static final int MAYBE_CHECK_THRESHOLD = 10;
+ private static final Interner<KeyToConsolidate> consolidateInterner = Interners.newWeakInterner();
+
abstract void setReverseDepsObject(T container, Object object);
abstract void setSingleReverseDep(T container, boolean singleObject);
@@ -72,7 +76,7 @@ public abstract class ReverseDepsUtil<T> {
*/
private abstract static class KeyToConsolidate {
// Do not access directly -- use the {@link #key} static accessor instead.
- private final SkyKey key;
+ protected final SkyKey key;
/** Do not call directly -- use the {@link #create} static method instead. */
private KeyToConsolidate(SkyKey key) {
@@ -110,25 +114,49 @@ public abstract class ReverseDepsUtil<T> {
case CHECK:
return key;
case REMOVE:
- return new KeyToRemove(key);
+ return consolidateInterner.intern(new KeyToRemove(key));
case ADD:
- return new KeyToAdd(key);
+ return consolidateInterner.intern(new KeyToAdd(key));
default:
throw new IllegalStateException(op + ", " + key);
}
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ return this.getClass() == obj.getClass() && this.key.equals(((KeyToConsolidate) obj).key);
+ }
+
+ @Override
+ public int hashCode() {
+ // Overridden in subclasses.
+ throw new UnsupportedOperationException(key.toString());
+ }
}
private static final class KeyToAdd extends KeyToConsolidate {
KeyToAdd(SkyKey key) {
super(key);
}
+
+ @Override
+ public int hashCode() {
+ return key.hashCode();
+ }
}
private static final class KeyToRemove extends KeyToConsolidate {
KeyToRemove(SkyKey key) {
super(key);
}
+
+ @Override
+ public int hashCode() {
+ return 42 + 37 * key.hashCode();
+ }
}
private void maybeDelayReverseDepOp(T container, Iterable<SkyKey> reverseDeps, ConsolidateOp op) {