trivial patch to reduce allocations in nio open* methods

Brian Burkhalter brian.burkhalter at oracle.com
Thu Jun 21 00:53:18 UTC 2018


On Jun 20, 2018, at 1:52 AM, Alan Bateman <Alan.Bateman at oracle.com> wrote:

>> 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?
>> 
>> 
> FileSystemProvider L430. This has been changed to create the HashSet with an initial capacity of len+1 so it's ignoring the load factor. I'm just saying that the 4 places where this has changed can be improved to avoid resizing every time.

My doubt is that I don’t see where these would ever be resized.

> Given that the number of options is small is almost all cases then it may be simpler to just use the no-arg constructor for now.

So changed (see below).

Thanks,

Brian

--- a/src/java.base/share/classes/java/nio/channels/AsynchronousFileChannel.java
+++ b/src/java.base/share/classes/java/nio/channels/AsynchronousFileChannel.java
@@ -308,1 +308,1 @@
-            set = new HashSet<>(options.length);
+            set = new HashSet<>();

--- a/src/java.base/share/classes/java/nio/channels/FileChannel.java
+++ b/src/java.base/share/classes/java/nio/channels/FileChannel.java
@@ -342,1 +342,1 @@
-            set = new HashSet<>(options.length);
+            set = new HashSet<>();

--- a/src/java.base/share/classes/java/nio/file/Files.java
+++ b/src/java.base/share/classes/java/nio/file/Files.java
@@ -417,1 +417,1 @@
-            set = new HashSet<>(options.length);
+            set = new HashSet<>();

--- a/src/java.base/share/classes/java/nio/file/spi/FileSystemProvider.java
+++ b/src/java.base/share/classes/java/nio/file/spi/FileSystemProvider.java
@@ -430,1 +430,1 @@
-            opts = new HashSet<>(len + 1);
+            opts = new HashSet<>();

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20180620/116a0441/attachment.html>


More information about the nio-dev mailing list