Skip to content

Commit

Permalink
Simplify ComponentDescriptor.hashCode() and memoize it
Browse files Browse the repository at this point in the history
For a very large internal component, saves roughly ~42 seconds on average (or 28%) over 10 runs.

Memoizing the hashCode isn't as stupendous, but profiles do show that memoizing reduces the cost of the hashCode by an additional 10x (after the already big savings): 80ms -> 7ms

RELNOTES=Build performance improvements

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=228529245
  • Loading branch information
ronshapiro committed Jan 15, 2019
1 parent 687370f commit 174a7a9
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions java/dagger/internal/codegen/ComponentDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.google.auto.common.MoreElements;
import com.google.auto.common.MoreTypes;
import com.google.auto.value.AutoValue;
import com.google.auto.value.extension.memoized.Memoized;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableBiMap;
Expand All @@ -56,6 +57,7 @@
import dagger.producers.CancellationPolicy;
import dagger.producers.ProductionComponent;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
import javax.inject.Inject;
Expand Down Expand Up @@ -251,6 +253,16 @@ final Optional<CancellationPolicy> cancellationPolicy() {
: Optional.empty();
}

@Memoized
@Override
public int hashCode() {
return Objects.hash(typeElement(), kind());
}

// TODO(ronshapiro): simplify the equality semantics
@Override
public abstract boolean equals(Object obj);

/** A function that returns all {@link #scopes()} of its input. */
@AutoValue
abstract static class ComponentMethodDescriptor {
Expand Down

0 comments on commit 174a7a9

Please sign in to comment.