←back to thread

253 points chhum | 1 comments | | HN request time: 0.21s | source
Show context
kaliszad ◴[] No.44007492[source]
The java.net.Inet4Address and Inet6Address could be more lightweight.

For a simple IPv4 address normally representable using 4 bytes/ 32 bits Java uses 56 bytes. The reason for it is Inet4Address object takes 24 B and the InetAddressHolder object takes another 32 B. The InetAddressHolder can contain not only the address but also the address family and original hostname that was possibly resolved to the address.

For an IPv6 address normally representable using 16 bytes/ 128 bits Java uses 120 bytes. An Inet6Address contains the InetAddressHolder inherited from InetAddress and adds an Inet6AddressHolder that has additional information such as the scope of the address and a byte array containing the actual address. This is an interesting approach especially when compared to the implementation of UUID, which uses two longs for storing the 128 bits of data.

Java's approach is causing 15x overhead for IPv4 and 7.5x overhead for IPv6 which seems excessive. What am I missing here? Can or should this be streamlined?

replies(2): >>44007797 #>>44012375 #
1. LtWorf ◴[] No.44012375[source]
Java is fast as long as you have near infinite RAM. When you don't it starts breaking apart.

The whole fixation of java developers to abstract things leads to countless virtual calls that are actually very slow at runtime.