Performance of NetworkInterface methods on Windows

DiCroce, Richard Rich.DiCroce at scientificgames.com
Tue Feb 7 21:04:02 UTC 2023


Hi Daniel,
I'm not proposing to add any caching, or change anything about the Java side of NetworkInterface, for exactly the reasons you state. This first patch is purely a change to the native code to make it so that getAll only calls the Windows API once instead of N + 1 times. createNetworkInterface actually already had parameters for passing the previously fetched list of interfaces. getAll just doesn't currently do that.

This would probably be easier to discuss if you could actually see the changes I'm proposing. Should I attach a patch to an email, or is there a better way of doing that?

Thanks,

Rich DiCroce
Senior Advanced Solutions Architect

Scientific Games


HAVE FUN. DO GOOD. PLAY HEALTHY.
 May be privileged. May be confidential. Please delete if not the addressee.


-----Original Message-----
From: Daniel Fuchs <daniel.fuchs at oracle.com> 
Sent: Tuesday, February 7, 2023 3:52 PM
To: DiCroce, Richard <Rich.DiCroce at scientificgames.com>; net-dev at openjdk.org
Subject: Re: Performance of NetworkInterface methods on Windows

WARNING: This is an external email. Do not click links or open attachments unless you recognize the sender and know the content is safe.


Hi Richard,

Welcome to OpenJDK :-)

A NetworkInterface object has a state, of which a subset is a snapshot of some information that was read and copied at the time the NetworkInterface object was created. Typically, the list of addresses bound to the interface is a snapshot.

Getting the entire NetworkInterface all over again ensures that the new interface object has a new refreshed snapshot of this state. It may not be the best implementation depending on what the calling code is trying to achieve, but this is a long standing behavior (even though unspecified) that cannot be changed without incurring high risk of regressions in existing applications.

I'm not sure what your patch is proposing to do - but I'm not sure it will be a pure performance fix without any impact on observable behavior.

Naively caching interfaces created by a previous call would not work, for instance.
There is certainly performance gains to be had, and making use of the new foreign memory API to reduce the number of upcalls could be an avenue to explore.
Backward compatibility is a concern to keep in mind though.

best regards,

-- daniel

PS: I see Alan has already replied on some other aspects
     of your inquiry.


On 07/02/2023 20:06, DiCroce, Richard wrote:
> Hi everyone,
>
> I’d like to propose a patch to fix a performance issue with 
> enumerating network interfaces on Windows. The problem stems from the 
> fact that getAll calls createNetworkInterface for every interface, but 
> does not pass the list of interfaces that it has already collected. As 
> a result, createNetworkInterface gets the entire list all over again.
>



More information about the net-dev mailing list