RFR: 8282662: Use List/Set.of() factory methods to reduce memory consumption
Сергей Цыпанов
duke at openjdk.java.net
Tue Mar 8 12:36:58 UTC 2022
On Mon, 7 Mar 2022 16:06:44 GMT, Claes Redestad <redestad at openjdk.org> wrote:
> Notice list.of will have the downside of copying the input array when the size is not small while arrays aslist does not. Is the tradeoff worth it?
Good point, I see risky changes in this PR:
- `ProxyGenerator`
- `Proxy`
- `MethodType`
- `FileTreeIterator`
As of `ProxyGenerator.ProxyMethod` at start-up time of my Spring Boot -based application there are 2696 invocations of `ProxyGenerator.ProxyMethod.generateMethod()` and 0 of them was for `exceptionTypes.length > 2`. This is expectable as the majority of the methods declare either 0, or 1-2 exceptions.
As of `Proxy.getProxyConstructor()` in my application I have 1417 invocations of `List.of()` and 599 of them are with `intfsArray.length > 2`. There were no invocations of `Proxy.defaultMethodHandle()` so I have no statistics.
For `MethodType` there were 0 invocations, and I have no statistics, but as of my experience most of the methods have 0-2 parameters.
In case of `FileTreeIterator` incoming vararg is always of length either 0 or 1, as `FileVisitOption` enum has only one item.
So I suggest to apply something like `intfsArray.length < 2 ? List.of(intfsArray) : Arrays.asList(intfsArray)` keeping the rest of the code as is.
What do you think?
-------------
PR: https://git.openjdk.java.net/jdk/pull/7729
More information about the nio-dev
mailing list