RFR: [6904367]: (coll) IdentityHashMap is resized before exceeding the expected maximum size
Jeff Hain
jeffhain at rocketmail.com
Mon Jul 14 00:24:46 UTC 2014
>Can you post the benchmark source?
Before the source, here are the time ranges runs were stabilizing in
for lucky executions (using 1.7 for compiler compliance level, and
win7 / core i7) :
| original | peter7 | peter7 | peter8 | peter8 |
| | | no loop | | no loop |
---------+----------+----------+----------+----------+----------+
jdk7u51 | 0.56-59s | 0.66-68s | 0.62-64s | 0.60-63s | 0.70-74s |
jdk8u20 | 0.54-58s | 0.64-66s | 0.58-60s | 0.58-61s | 0.73-76s |
jdk9 | 0.59-61s | 0.65-67s | 0.73-75s | 0.60-63s | 0.76-78s |
=> The no-loop version seems only better for jdk <= 8 and your webrev 07,
and for webrev 08, it seems actually (much) worse whatever the jdk.
=> jdk 8 looks faster than 7, but for some reason also faster than 9.
public class IdentityHashMapPerf {
private static final int MAX_NBR_OF_MAPPINGS = 1*1000;
private static final int MAX_NBR_OF_CALLS = 100*1000*1000;
private static final int NBR_OF_RUNS = 10;
public static void main(String[] args) {
System.out.println(IdentityHashMapPerf.class.getSimpleName()+"...");
for (int k=0;k<NBR_OF_RUNS;k++) {
// Quick run for code discovery for k = 0.
final int maxNbrOfCalls = (k == 0) ? MAX_NBR_OF_MAPPINGS
: MAX_NBR_OF_CALLS;
bench_put(new IdentityHashMap<Integer, Integer>(), maxNbrOfCalls);
//bench_put(new IdentityHashMapPeter7<Integer, Integer>(), maxNbrOfCalls);
//bench_put(new IdentityHashMapPeter7NoLoop<Integer, Integer>(), maxNbrOfCalls);
//bench_put(new IdentityHashMapPeter8<Integer, Integer>(), maxNbrOfCalls);
//bench_put(new IdentityHashMapPeter8NoLoop<Integer, Integer>(), maxNbrOfCalls);
}
System.out.println("..."+IdentityHashMapPerf.class.getSimpleName());
}
private static void bench_put(Map<Integer, Integer> map, int maxNbrOfCalls) {
for (int k=0;k<2;k++) {
final Integer[] keys = newKeys(MAX_NBR_OF_MAPPINGS);
final int nbrOfClearAndPuts = maxNbrOfCalls/MAX_NBR_OF_MAPPINGS;
long a = System.nanoTime();
{
for (int cap=0;cap<nbrOfClearAndPuts;cap++) {
map.clear();
for (int i=0;i<MAX_NBR_OF_MAPPINGS;i++) {
final Integer kv = keys[i];
map.put(kv, kv);
}
if (map.size() != MAX_NBR_OF_MAPPINGS) {
throw new AssertionError("anti optim");
}
}
}
long b = System.nanoTime();
System.out.println(nbrOfClearAndPuts+" * "+MAX_NBR_OF_MAPPINGS
+" "+map.getClass().getSimpleName()+".put(,) took "+((b-a)/1e9)+" s");
}
}
private static Integer[] newKeys(int size) {
final Integer[] keys = new Integer[size];
for (int i=0;i<keys.length;i++) {
keys[i] = i;
}
return keys;
}
}
-Jeff
More information about the core-libs-dev
mailing list