Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

37
LINES

< > BotCompany Repo | #1034270 // bench_concurrentHashMapBasedMethodCache_tweaked

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (5766L) is out of date.

// Default load factor but only 1 concurrent thread anticipated.
// This gives ~48 mill/s cache lookups
static final ConcurrentHashMap<Class, _MethodCache> getMethodCache_chm
  = new ConcurrentHashMap(16, 0.75f, 1);
  
// Let's try load factor 0.5.
// This seems a bit worse - something around 42 mill/s or so.
/*static final ConcurrentHashMap<Class, _MethodCache> getMethodCache_chm
  = new ConcurrentHashMap(16, 0.5f, 1);*/

// Let's try load factor 0.25 just for fun.
// Gives ~47 mill/s or so. So I guess the load factor of 0.75 is fine.
/*static final ConcurrentHashMap<Class, _MethodCache> getMethodCache_chm
  = new ConcurrentHashMap(16, 0.25f, 1);*/

static _MethodCache getMethodCache_chm(Class c) {
  _MethodCache cache = getMethodCache_chm.get(c);
  if (cache == null)
    getMethodCache_chm.put(c, cache = _MethodCache(c));
  ret cache;
}

// This one gets ~44 mill/s cache lookups which is definitely better than the old method
svoid bench_concurrentHashMapBasedMethodCache_tweaked() {
  print("Loading 1000 classes");
  L<Class> classes = map classForName(takeFirst(1000, classNamesInJigsawModule("java.base")));
  print("Have " + nClasses(classes) + ". Filling method caches");
  time {
    for (c : classes) assertNotNull(getMethodCache_chm(c));
  }
  print("Looking them up again.");
  benchFor10(-> {
    for (c : classes) assertNotNull(getMethodCache_chm(c));
  });

  print("Classes in method cache: " + l(getMethodCache_chm));
}

Author comment

Began life as a copy of #1034269

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034270
Snippet name: bench_concurrentHashMapBasedMethodCache_tweaked
Eternal ID of this version: #1034270/10
Text MD5: 862d6e0397067332e5460e0571554c25
Author: stefan
Category: javax / performance
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-29 16:15:46
Source code size: 1485 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 133 / 229
Version history: 9 change(s)
Referenced in: [show references]