aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2017-11-30 07:15:05 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-11-30 07:17:39 -0800
commit5670fb29734483f8d2008cb01dddc5f3dd129cf9 (patch)
tree0430e14fe9bdf942e1ed346f63c4c1cf89012e87
parent16a5bd9fde00a418e16f30e18270aeb198d36218 (diff)
Simplify tagged event handling.
Don't make copies of Events on replay. The same events may be replayed a lot, so it's better to copy before storing the events. Also avoid a copy if the tag doesn't actually change. The intent of this change is to reduce gc churn on incremental builds. When I wrote this change (~a year ago), this was a noticable source of gc churn in some benchmarks I ran at the time. PiperOrigin-RevId: 177450696
-rw-r--r--src/main/java/com/google/devtools/build/lib/events/Event.java3
-rw-r--r--src/main/java/com/google/devtools/build/skyframe/ParallelEvaluatorContext.java3
-rw-r--r--src/main/java/com/google/devtools/build/skyframe/TaggedEvents.java41
3 files changed, 25 insertions, 22 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/events/Event.java b/src/main/java/com/google/devtools/build/lib/events/Event.java
index 61db7dcad9..5bf5b1dd05 100644
--- a/src/main/java/com/google/devtools/build/lib/events/Event.java
+++ b/src/main/java/com/google/devtools/build/lib/events/Event.java
@@ -66,6 +66,9 @@ public final class Event implements Serializable {
}
public Event withTag(String tag) {
+ if (Objects.equals(tag, this.tag)) {
+ return this;
+ }
if (this.message != null) {
return new Event(this.kind, this.location, this.message, tag);
} else {
diff --git a/src/main/java/com/google/devtools/build/skyframe/ParallelEvaluatorContext.java b/src/main/java/com/google/devtools/build/skyframe/ParallelEvaluatorContext.java
index 840b5801e4..6860433c01 100644
--- a/src/main/java/com/google/devtools/build/skyframe/ParallelEvaluatorContext.java
+++ b/src/main/java/com/google/devtools/build/skyframe/ParallelEvaluatorContext.java
@@ -231,9 +231,8 @@ class ParallelEvaluatorContext {
@Override
public void accept(TaggedEvents events) {
- String tag = events.getTag();
for (Event e : events.getEvents()) {
- reporter.handle(e.withTag(tag));
+ reporter.handle(e);
}
}
}
diff --git a/src/main/java/com/google/devtools/build/skyframe/TaggedEvents.java b/src/main/java/com/google/devtools/build/skyframe/TaggedEvents.java
index bf5fc69798..0d3e422b65 100644
--- a/src/main/java/com/google/devtools/build/skyframe/TaggedEvents.java
+++ b/src/main/java/com/google/devtools/build/skyframe/TaggedEvents.java
@@ -13,10 +13,10 @@
// limitations under the License.
package com.google.devtools.build.skyframe;
+import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableCollection;
-import com.google.common.collect.Iterables;
+import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.events.Event;
-
import java.io.Serializable;
import java.util.Objects;
import javax.annotation.Nullable;
@@ -33,23 +33,21 @@ import javax.annotation.concurrent.Immutable;
*/
@Immutable
public final class TaggedEvents implements Serializable {
+ private final ImmutableList<Event> events;
+ private final int hashCode;
- @Nullable
- private final String tag;
- private final ImmutableCollection<Event> events;
-
- TaggedEvents(@Nullable String tag, ImmutableCollection<Event> events) {
-
- this.tag = tag;
- this.events = events;
+ TaggedEvents(final @Nullable String tag, ImmutableCollection<Event> events) {
+ this.events =
+ events.isEmpty()
+ ? ImmutableList.of()
+ : ImmutableList.copyOf(
+ Collections2.transform(
+ events,
+ (Event e) -> e.withTag(tag)));
+ this.hashCode = events.hashCode();
}
- @Nullable
- String getTag() {
- return tag;
- }
-
- ImmutableCollection<Event> getEvents() {
+ ImmutableList<Event> getEvents() {
return events;
}
@@ -59,20 +57,23 @@ public final class TaggedEvents implements Serializable {
*/
@Override
public String toString() {
- return tag == null ? "<unknown>" : tag + ": " + Iterables.toString(events);
+ return events.toString();
}
@Override
public int hashCode() {
- return Objects.hash(tag, events);
+ return hashCode;
}
@Override
public boolean equals(Object other) {
- if (other == null || !other.getClass().equals(getClass())) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof TaggedEvents)) {
return false;
}
TaggedEvents that = (TaggedEvents) other;
- return Objects.equals(this.tag, that.tag) && Objects.equals(this.events, that.events);
+ return (hashCode == that.hashCode) && Objects.equals(this.events, that.events);
}
}