Add lazily-instantiated maps
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 4 May 2020 12:34:27 +0000 (14:34 +0200)
committerAnil Belur <abelur@linuxfoundation.org>
Wed, 19 Jun 2024 00:41:32 +0000 (10:41 +1000)
commit6f6730afed7fd646606a73ce1e1adc247a0d0abb
treee7432f8160f21a257117f37ba8a3bb00fa998e9f
parentd403f0a899970e5b608f20b624309db6569e1fa9
Add lazily-instantiated maps

Instantiating an ImmutableMap on each access is quite wasteful,
as there are a number of cases where we do not need the entire
mapping to be instantiated.

Typical uses touch the Map only once -- either to lookup a value
based on the key, or to iterate through the values. Others are
possible, but those two cover most of the patterns.

We add the prerequisite indirection and two implementations to
support each of the cases. The iterator part is optimized to
perform lazy object instantiation -- similar to LazyBindingList.

The lookup part works in a rather similar way, except it keeps
a lookup ConcurrentHashMap as the primary storage and values
are seen as expendable secondary storage. This makes iteration
order unstable, which might be seen as a violation of immutable
contract -- but our contract is a Map and mappings remain stable.

JIRA: MDSAL-539
Change-Id: I7c095065915f3c0d7b180d4aa1494e15d6374a11
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingToNormalizedStreamWriter.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/CodecDataObject.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/KeyedListNodeCodecContext.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/LazyBindingList.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/LazyBindingMap.java [new file with mode: 0644]
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/LazyBindingMapIterState.java [new file with mode: 0644]
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/LazyBindingMapLookupState.java [new file with mode: 0644]
binding/mdsal-binding-dom-codec/src/test/java/org/opendaylight/mdsal/binding/dom/codec/impl/LazyBindingMapTest.java [new file with mode: 0644]