Skip to content

Commit

Permalink
Reduce lock contention on IsolatedOptionsData
Browse files Browse the repository at this point in the history
We see _serious_ lock contention on this method on certain synthetic
builds.

PiperOrigin-RevId: 246320016
  • Loading branch information
ulfjack authored and copybara-github committed May 2, 2019
1 parent 8a48b27 commit 27fad93
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.annotation.concurrent.Immutable;

/**
Expand Down Expand Up @@ -53,11 +55,11 @@ public class IsolatedOptionsData extends OpaqueOptionsData {
* instances, and must be used through the thread safe {@link
* #getAllOptionDefinitionsForClass(Class)}
*/
private static final Map<Class<? extends OptionsBase>, ImmutableList<OptionDefinition>>
allOptionsFields = new HashMap<>();
private static final ConcurrentMap<Class<? extends OptionsBase>, ImmutableList<OptionDefinition>>
allOptionsFields = new ConcurrentHashMap<>();

/** Returns all {@code optionDefinitions}, ordered by their option name (not their field name). */
public static synchronized ImmutableList<OptionDefinition> getAllOptionDefinitionsForClass(
public static ImmutableList<OptionDefinition> getAllOptionDefinitionsForClass(
Class<? extends OptionsBase> optionsClass) {
return allOptionsFields.computeIfAbsent(
optionsClass,
Expand Down

0 comments on commit 27fad93

Please sign in to comment.