JDK-8225239 : Refactor NetworkInterface lookups
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 8u212,11,13
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-06-04
  • Updated: 2021-10-20
  • Resolved: 2019-07-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 14
14 b05Fixed
Related Reports
Relates :  
Relates :  
Description
JDK-8223214 changed logic around to cause a slight increase in classes loaded when calling InetAddress.getLoopbackAddress(), which can be linked to a tiny footprint increase in 13-b22 since these classes end up in the default CDS archive.

We can recuperate slightly by arranging so that we don't load Inet4AddressImpl unnecessarily from Inet4AddressImpl etc.

A related inefficiency is that the call to NetworkInterface.getByInetAddress is inefficient since it enumerates and loops over all IPv4 and IPv6 interfaces, regardless of the type of address we're looking up. This is pre-existing, but JDK-8223214 puts it up there. How costly this superfluous enumeration is depends on the system you're on and it's network configuration, but I get a small improvement (~0.1ms) on startup from a patch that only searches the relevant interfaces. 
Comments
URL: http://hg.openjdk.java.net/jdk/jdk/rev/d01b345865d7 User: redestad Date: 2019-07-05 11:34:16 +0000
05-07-2019

When implementing and testing out the optimization for Windows, I noticed the current cost of various NetworkInterface APIs to be much more expensive on Windows than other platforms. Use of old Windows APIs may be partially to blame, but there's also an effectively quadratic scaling issue in the JNI code in that the IP address table is resolved once per attached adapter/interface. Refactoring to avoid this drops cost of some calls from ~100ms to ~10ms on systems with numerous network interfaces, while the isBoundInetAddress API costs about 3ms on the same system: http://cr.openjdk.java.net/~redestad/8225239/open.01/
04-07-2019

PoC patch with microbenchmark, improving bootstrap time of apps calling InetAddress.loopbackAddress(): http://cr.openjdk.java.net/~redestad/8225239/open.00/
05-06-2019