DEFAULT_MAX_BUCKETS based on max heap size

MAX_DEFAULT_BUCKETS is linearly correlated to max heap size with a minimum of 256 buckets.
This commit is contained in:
Konstantinos Chalkias 2017-03-16 16:40:34 +00:00 committed by GitHub
parent 391270ed71
commit 5966610a6e

View File

@ -21,11 +21,12 @@ import kotlin.system.measureTimeMillis
/**
* The default maximum size of the LRU cache.
* Current computation is linear to max heap size, ensuring a minimum of 256 buckets.
*
* TODO: make this value configurable
* TODO: tune this value, as it's currently mostly a guess
*/
val DEFAULT_MAX_BUCKETS = 4096
val DEFAULT_MAX_BUCKETS = (256 * (1 + Math.max(0, (Runtime.getRuntime().maxMemory()/1000000 - 128) / 64))).toInt()
/**
* A convenient JDBC table backed hash map with iteration order based on insertion order.