Skip to content

Commit

Permalink
Use ConcurrentSkipListMap in Model for knowledge
Browse files Browse the repository at this point in the history
The knowledge cache previously used a synchronized IdentityMap to cache
knowledge indexes. ConcurrentHashMap was not used because
computeIfAbsent needed to be called recursively when creating indexes,
and that doesn't work with ConcurrentHashMap. However,
ConcurrentSkipListMap can be work with recursive calls to
computeIfAbsent.
  • Loading branch information
mtdowling authored and Michael Dowling committed Mar 28, 2022
1 parent a3317c0 commit 52818ac
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
import java.util.AbstractSet;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.function.Function;
import java.util.stream.Stream;
import software.amazon.smithy.model.knowledge.KnowledgeIndex;
Expand Down Expand Up @@ -87,7 +88,7 @@ public final class Model implements ToSmithyBuilder<Model> {

/** Cache of computed {@link KnowledgeIndex} instances. */
private final Map<Class<? extends KnowledgeIndex>, KnowledgeIndex> blackboard
= Collections.synchronizedMap(new IdentityHashMap<>());
= new ConcurrentSkipListMap<>(Comparator.comparing(Class::getCanonicalName));

/** Lazily computed trait mappings. */
private volatile TraitCache traitCache;
Expand Down

0 comments on commit 52818ac

Please sign in to comment.