Memory optimization: Fewer ConcurrentHashMap.Segment instances

This commit is contained in:
Andrey Breslav
2014-11-01 13:40:13 +02:00
parent 60ff2df597
commit 87d372aad5
@@ -101,7 +101,7 @@ public class LockBasedStorageManager implements StorageManager {
@NotNull
@Override
public <K, V> MemoizedFunctionToNotNull<K, V> createMemoizedFunction(@NotNull Function1<? super K, ? extends V> compute) {
return createMemoizedFunction(compute, new ConcurrentHashMap<K, Object>());
return createMemoizedFunction(compute, LockBasedStorageManager.<K>createConcurrentHashMap());
}
@NotNull
@@ -115,7 +115,13 @@ public class LockBasedStorageManager implements StorageManager {
@NotNull
@Override
public <K, V> MemoizedFunctionToNullable<K, V> createMemoizedFunctionWithNullableValues(@NotNull Function1<? super K, ? extends V> compute) {
return createMemoizedFunctionWithNullableValues(compute, new ConcurrentHashMap<K, Object>());
return createMemoizedFunctionWithNullableValues(compute, LockBasedStorageManager.<K>createConcurrentHashMap());
}
@NotNull
private static <K> ConcurrentMap<K, Object> createConcurrentHashMap() {
// memory optimization: fewer segments and entries stored
return new ConcurrentHashMap<K, Object>(3, 1, 2);
}
@NotNull