Number of elements allowed in NodeWithKey equals to the number of leaf
nodes specified in the 'key' statement. It is usually a small number of
elements, but these tend to have many instances.
This patch optimizes memory usage with more than one key leaf. Instead
of an ImmutableMap, in which each instance has its own unique key set,
we use an ImmutableOffsetMap, which shares the key set across all
instances. The cost here is a LoadingCache lookup which should prove
neglible.
Change-Id: I68afe667415ba1eaddbb081b419fedcae4e4b8f7
Signed-off-by: Robert Varga <rovarga@cisco.com>
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.concepts.Path;
import org.opendaylight.yangtools.util.HashCodeBuilder;
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.concepts.Path;
import org.opendaylight.yangtools.util.HashCodeBuilder;
+import org.opendaylight.yangtools.util.ImmutableOffsetMap;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
public NodeIdentifierWithPredicates(final QName node, final Map<QName, Object> keyValues) {
super(node);
public NodeIdentifierWithPredicates(final QName node, final Map<QName, Object> keyValues) {
super(node);
- this.keyValues = ImmutableMap.copyOf(keyValues);
+ // Retains ImmutableMap for maps with size() <= 1. For larger sizes uses a shared key set.
+ this.keyValues = ImmutableOffsetMap.copyOf(keyValues);
}
public NodeIdentifierWithPredicates(final QName node, final QName key, final Object value) {
}
public NodeIdentifierWithPredicates(final QName node, final QName key, final Object value) {