Class ICUResourceBundleReader.ResourceCache

java.lang.Object
com.ibm.icu.impl.ICUResourceBundleReader.ResourceCache
Enclosing class:
ICUResourceBundleReader

private static final class ICUResourceBundleReader.ResourceCache extends Object
Cache of some of one resource bundle's resources. Avoids creating multiple Java objects for the same resource items, including multiple copies of their contents.

Mutable objects must not be cached and then returned to the caller because the cache must not be writable via the returned reference.

Resources are mapped by their resource integers. Empty resources with offset 0 cannot be mapped. Integers need not and should not be cached. Multiple .res items may share resource offsets (genrb eliminates some duplicates).

Large resource objects are usually stored in SoftReferences.

This replaces the previous custom trie structure (ICU-10932, 2014) with ConcurrentHashMap for lock-free concurrent reads. Benchmarking shows CHM uses ~3x less memory than the trie at typical ICU bundle sizes (~221 entries/cache) due to the trie's sparse power-of-2 Level arrays (5% utilization), while providing ~2x better throughput at 32 threads by eliminating the synchronized bottleneck on every resource lookup.

  • Field Details

  • Constructor Details

    • ResourceCache

      ResourceCache()
  • Method Details

    • storeDirectly

      private static boolean storeDirectly(int size)
    • get

      Object get(int res)
    • putIfAbsent

      Object putIfAbsent(int res, Object item, int size)
    • deduplicateTableArrays

      void deduplicateTableArrays()
    • deduplicateItem

      private static Object deduplicateItem(Object value, Map<CharBuffer, char[]> charMap, Map<IntBuffer, int[]> intMap, Map<String,String> stringMap)