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.

1  
// Default load factor but only 1 concurrent thread anticipated.
2  
// This gives ~48 mill/s cache lookups
3  
static final ConcurrentHashMap<Class, _MethodCache> getMethodCache_chm
4  
  = new ConcurrentHashMap(16, 0.75f, 1);
5  
  
6  
// Let's try load factor 0.5.
7  
// This seems a bit worse - something around 42 mill/s or so.
8  
/*static final ConcurrentHashMap<Class, _MethodCache> getMethodCache_chm
9  
  = new ConcurrentHashMap(16, 0.5f, 1);*/
10  
11  
// Let's try load factor 0.25 just for fun.
12  
// Gives ~47 mill/s or so. So I guess the load factor of 0.75 is fine.
13  
/*static final ConcurrentHashMap<Class, _MethodCache> getMethodCache_chm
14  
  = new ConcurrentHashMap(16, 0.25f, 1);*/
15  
16  
static _MethodCache getMethodCache_chm(Class c) {
17  
  _MethodCache cache = getMethodCache_chm.get(c);
18  
  if (cache == null)
19  
    getMethodCache_chm.put(c, cache = _MethodCache(c));
20  
  ret cache;
21  
}
22  
23  
// This one gets ~44 mill/s cache lookups which is definitely better than the old method
24  
svoid bench_concurrentHashMapBasedMethodCache_tweaked() {
25  
  print("Loading 1000 classes");
26  
  L<Class> classes = map classForName(takeFirst(1000, classNamesInJigsawModule("java.base")));
27  
  print("Have " + nClasses(classes) + ". Filling method caches");
28  
  time {
29  
    for (c : classes) assertNotNull(getMethodCache_chm(c));
30  
  }
31  
  print("Looking them up again.");
32  
  benchFor10(-> {
33  
    for (c : classes) assertNotNull(getMethodCache_chm(c));
34  
  });
35  
36  
  print("Classes in method cache: " + l(getMethodCache_chm));
37  
}

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: 71 / 145
Version history: 9 change(s)
Referenced in: [show references]