Introduce SharedSingletonMap
ImmutableMap can be very expensive in terms of memory overhead when
storing a large number of singleton maps which have the same keySet(),
because it instantiates an ImmutableSet, which remains cached. That ends
up costing 24 bytes in local testing.
This patch implements a replacement class which retains the same
properties, but shares the keySet instances -- thus lowering the overall
overhead. For these instances we introduce an SingletonSet class, which
is memory-efficient and gives us direct access to the container entry.
This leaves entrySet() as the only method which allocates objects. We do
not cache returned objects in the expectation any caller users them as
pure DTOs, hence they end up being cheap.
Change-Id: I64e74d8e661d2689d32bea31e1cdf72e87ed64af
Signed-off-by: Robert Varga <rovarga@cisco.com>