Skip to content

Commit

Permalink
bazel syntax: memoize StarlarkSemantics.hashCode
Browse files Browse the repository at this point in the history
Recomputing it accounted for +5% CPU. (I had assumed ImmutableSortedMap would
cache it, but I guessed wrong. I suppose it must account for its elements being mutable.)

PiperOrigin-RevId: 331145205
  • Loading branch information
adonovan authored and copybara-github committed Sep 11, 2020
1 parent 95704d1 commit 83034fa
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ public final class StarlarkSemantics {
// Key<Boolean> is permitted too.
// We use ImmutableSortedMap for the benefit of equals/hashCode/toString.
private final ImmutableSortedMap<String, Object> map;
private final int hashCode;

private StarlarkSemantics(ImmutableSortedMap<String, Object> map) {
this.map = map;
this.hashCode = map.hashCode();
}

/** Returns the value of a boolean option, which must have a [+-] prefix. */
Expand Down Expand Up @@ -169,7 +171,7 @@ boolean isFeatureEnabledBasedOnTogglingFlags(String enablingFlag, String disabli

@Override
public int hashCode() {
return map.hashCode();
return hashCode;
}

@Override
Expand Down

0 comments on commit 83034fa

Please sign in to comment.