trivial patch to reduce allocations in nio open* methods

Brian Burkhalter brian.burkhalter at oracle.com
Wed Jun 20 00:23:53 UTC 2018


Picking up this thread from [1] after a few months. A new patch is available at [2]. The changes versus version .00 are at [3].

On Mar 30, 2018, at 1:27 AM, Alan Bateman <Alan.Bateman at oracle.com> wrote:

> On 30/03/2018 02:11, Brian Burkhalter wrote:
>> I created a webrev of this patch:
>> 
>> http://cr.openjdk.java.net/~bpb/8199124/webrev.00/ <http://cr.openjdk.java.net/%7Ebpb/8199124/webrev.00/>
>> 
>> I don’t see any problem in moving forward with it, possibly with some minor cleanup.
>> 
> Just a few comments.
> 
> The sizing of the hash map doesn't take the load factor into account. You might find `new HashMap<>(1 + (4 * options.length/ 3)` a bit better with a larger array of options.

I don’t see what you are referring to. There is no use of HashMap in these classes. The HashSets are created to be of a fixed size as they are not resized later. Perhaps Set.of(E… elements) should be used to create these Sets?

> You can use an immutable set to avoid wrapping the EnumSet, e.g.
>     private static final Set<OpenOption> DEFAULT_CREATE_OPTIONS = Set.of(CREATE_NEW, WRITE);

The two occurrences like this are changed according to the suggestion.

Thanks,

Brian

[1] http://mail.openjdk.java.net/pipermail/nio-dev/2018-March/004950.html
[2] http://cr.openjdk.java.net/~bpb/8199124/webrev.01/
[3] http://cr.openjdk.java.net/~bpb/8199124/webrev.00-01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20180619/498366a8/attachment.html>


More information about the nio-dev mailing list