I’m staring at a profile where one of the CPU hot-spots is a function that consists of cloning a final static int[]. You might ask, ‘Why?’ the callers use the results as the starting points of a hashing process.
In other words, the code needs to do (logically):
- make a new array
- get the hash seeds (as many as the size of the array)
- put values in the new array calculated from the hash seeds. That’s an iterative
algorithm, so it’s advantageous to have the seeds start out in the array — and thus the idea of starting with a clone of the array of seeds.
Before I either give up or start wrting microbenchmarks, I’m posting this question in case anyone has any special knowledge of the what’s under the hood with clone() versus Arrays.copyOf versus just new and an arraycopy.
Arrays.copyOfusesSystem.arraycopybut adds some boundchecks firstI got this from http://www.docjar.com/docs/api/java/util/Arrays.html so it might be marginally better to use this than the
Arrays.copyOfthough really it might be best to keep the arrays and reuse them after they are done with them