-
toCharArray
will copy theString
into achar[]
every time, entirely unnecessary. -
Don’t use
String
to store bits or numbers. If you have less than 32 bits, use anint
. If you have less than 64 bits, use along
. If more, use along[]
. -
Try some optimizations based on bit operations. For example, you can compute the Hamming distance with a simple bit count and xor operation. You can also get a cheap lower bound based on the number of set bits – if one has 6 bits, the other 2, at least 4 bits have to be different.
-
Avoid
ArrayList<Integer>
andArrayList<Vertex>
. These need roughly 20 bytes per integer rather than 4. That is 400% overhead. Useint[]
+size
, double array if full (ArrayList does the same, but uses boxed integers).
Use a profiler such as visualvm to see where you wastw memory.
My guess is that String [][] dist2 = new String[200000][276];
is to blame. 200000*276*50 is probably enough to eat all your memory. Get rid of useless strings!