An instance of HashMap has two parameters that affect its performance: initial capacity and load factor. The capacity is the number of buckets in the hash table, and the initial capacity is simply the capacity at the time the hash table is created. The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased. When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the hash table is rehashed (that is, internal data structures are rebuilt) so that the hash table has approximately twice the number of buckets.
As a general rule, the default load factor (.75) offers a good tradeoff between time and space costs. Higher values decrease the space overhead but increase the lookup cost (reflected in most of the operations of the HashMap class, including get and put). The expected number of entries in the map and its load factor should be taken into account when setting its initial capacity, so as to minimize the number of rehash operations. If the initial capacity is greater than the maximum number of entries divided by the load factor, no rehash operations will ever occur.
If many mappings are to be stored in a HashMap instance, creating it with a sufficiently large capacity will allow the mappings to be stored more efficiently than letting it perform automatic rehashing as needed to grow the table.
Note that this implementation is not synchronized. If multiple threads access a hash map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with a key that an instance already contains is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the map. If no such object exists, the map should be "wrapped" using the Collections.synchronizedMap method. This is best done at creation time, to prevent accidental unsynchronized access to the map:
总结，Hashmap有两个参数可以调整，initial capacity and load factor.。另外一方面，我们的Hashmap元素比较多，所以把它的初始化大小调整大一些，应该可以改善存储效率。
另外 Performance ConcurrentHashmap vs HashMap 两个Map的性能比较可以参考
- Reading and writing from
HashMapwith 1 thread access is similarly effective
- Writing to
ConcurrentHashMapby 6 threads is just a little bit slower than writing to separate
- Reading from
ConcurrentHashMapby 6 threads is slower (about 3x) than reading from single
ConcurrentHashMapby a single thread. Still the access time is very, very good.It is 0,13s vs 0,3s for reading 1.000.000 entries from a Map.
To sum up, the performance for
ConcurrentHashMap is slightly worse when you need to use it from more than one thread but it is not a critical aspect of performance that you should be worried about.