calrissian / mango

Common utilities for rapid application development
Apache License 2.0
17 stars 7 forks source link

IP classes should be caching the byteArray used for comparisons instead of the InetAddress #183

Closed eawagner closed 9 years ago

eawagner commented 9 years ago

The reason for this is that every comparison uses the byte array from InetAddress.getAddress().

The problem is that this method generates a new byte array for each address in the comparison. This happens for every comparison, causing a lot of small byte arrays to get created on the heap. It is better to simply cache the byte array to make the comparison operations faster.

eawagner commented 9 years ago

I would like to investigate this further, with good benchmarking.

cjnolet commented 9 years ago

LRUCache?

eawagner commented 9 years ago

I was thinking just to store the byte arrays as class variables, so that we didn't create new arrays every time toByteArray() was called. Potentially, instead of storing the underlying InetAddress class, as that is simply redundant

That being said, the overhead of creating such small arrays is very small, so I want to run some benchmarks to see what the benefits are to different approaches.