Re: RFR: 8343559: Optimize Class.getMethod(String, Class...) for methods with no-arg [v3]

2024-11-07 Thread jengebr
.250 ns/op > ClassGetMethod.getIntfNoArgavgt6 205.565 ± 9.140 ns/op > ClassGetMethod.getNoSuchMethod avgt 10 2231.248 ± 67.711 ns/op > ClassGetMethod.getSuperFiveArg avgt6 169.971 ± 0.883 ns/op > ClassGetMethod.getSuperNoArg avgt6 129.18

Re: RFR: 8343559: Optimize Class.getMethod(String, Class...) for methods with no-arg [v3]

2024-11-07 Thread jengebr
On Wed, 6 Nov 2024 17:35:36 GMT, Chen Liang wrote: >> I don't like the style of a custom loop rather than `Arrays.equals()` but >> there is a perf benefit to it. Curious what you think? > > Sure, moving param count ahead is fine. Note that `Arrays.equals` is subject > to profile pollution at

Re: RFR: 8343559: Optimize Class.getMethod(String, Class...) for methods with no-arg [v2]

2024-11-06 Thread jengebr
On Wed, 6 Nov 2024 17:35:36 GMT, Chen Liang wrote: > Note that Arrays.equals is subject to profile pollution at runtime, so the > benchmark results might not be applicable in practice. Good point, thank you. Should I stick with `Arrays.equals()` on the basis that it's more intuitive, and the

Re: RFR: 8343559: Optimize Class.getMethod(String, Class...) for methods with no-arg [v2]

2024-11-06 Thread jengebr
On Wed, 6 Nov 2024 17:28:08 GMT, jengebr wrote: >> src/java.base/share/classes/java/lang/PublicMethods.java line 108: >> >>> 106:Class[] ptypes) { >>> 107: // check for matching param types length, then name, then &

Re: RFR: 8343559: Optimize Class.getMethod(String, Class...) for methods with no-arg [v2]

2024-11-06 Thread jengebr
On Wed, 6 Nov 2024 15:19:31 GMT, Chen Liang wrote: >> jengebr has updated the pull request incrementally with three additional >> commits since the last revision: >> >> - Optimizing filter logic by internalizing loop >> - Enhancing benchmark + tests with additio

Re: RFR: 8343559: Optimize Class.getMethod(String, Class...) for methods with no-arg [v2]

2024-11-06 Thread jengebr
lassGetMethod.getNoSuchMethod avgt 10 2158.844 ± 43.716 ns/op > ClassGetMethod.getSuperFiveArg avgt 6 129.047 ± 4.414 ns/op > ClassGetMethod.getSuperNoArg avgt6 123.728 ± 6.182 ns/op jengebr has updated the pull request incrementally with three additional commi

Re: RFR: 8343559: Optimize Class.getMethod(String, Class...) for methods with no-arg

2024-11-06 Thread jengebr
On Wed, 6 Nov 2024 15:20:42 GMT, Chen Liang wrote: >> This change optimizes the runtime of `Class.getMethod(String, Class[])` >> in two ways: >> >> 1. While iterating across each Method to find a match (existing logic) it >> now compares parameter count before checking method name. This check

Re: RFR: 8343559: Optimize Class.getMethod(String, Class...) for methods with no-arg

2024-11-06 Thread jengebr
On Wed, 6 Nov 2024 14:15:42 GMT, jengebr wrote: > This change optimizes the runtime of `Class.getMethod(String, Class[])` in > two ways: > > 1. While iterating across each Method to find a match (existing logic) it now > compares parameter count before checking method name.

RFR: 8343559: Optimize Class.getMethod(String, Class...) for methods with no-arg

2024-11-06 Thread jengebr
This change optimizes the runtime of `Class.getMethod(String, Class[])` in two ways: 1. While iterating across each Method to find a match (existing logic) it now compares parameter count before checking method name. This check is substantially faster. 2. While iterating (existing logic) if th

Integrated: 8332842: Optimize empty CopyOnWriteArrayList allocations

2024-08-14 Thread jengebr
On Mon, 3 Jun 2024 16:47:20 GMT, jengebr wrote: > Improve `java/util/concurrent/CopyOnWriteArrayList` by eliminating needless > cloning of Object[0] instances. This cloning is intended to prevent callers > from changing array contents, but many `CopyOnWriteArrayList`s are allocated

Re: RFR: 8332842: Optimize empty CopyOnWriteArrayList allocations [v4]

2024-08-14 Thread jengebr
On Thu, 20 Jun 2024 19:17:25 GMT, jengebr wrote: >> Improve `java/util/concurrent/CopyOnWriteArrayList` by eliminating needless >> cloning of Object[0] instances. This cloning is intended to prevent callers >> from changing array contents, but many `CopyOnWriteArrayList`s ar

Re: RFR: 8332842: Optimize empty CopyOnWriteArrayList allocations [v3]

2024-08-13 Thread jengebr
On Wed, 19 Jun 2024 12:52:46 GMT, Alan Bateman wrote: >> @AlanBateman -- could you please take a look? Thanks. > >> @AlanBateman -- could you please take a look? Thanks. > > There was a lot of heap analysis done a few years ago that shined a light on > the number of empty collections in a typic

Re: RFR: 8332842: Optimize empty CopyOnWriteArrayList allocations [v4]

2024-08-12 Thread jengebr
On Thu, 20 Jun 2024 19:17:25 GMT, jengebr wrote: >> Improve `java/util/concurrent/CopyOnWriteArrayList` by eliminating needless >> cloning of Object[0] instances. This cloning is intended to prevent callers >> from changing array contents, but many `CopyOnWriteArrayList`s ar

Re: RFR: 8332842: Optimize empty CopyOnWriteArrayList allocations [v3]

2024-07-15 Thread jengebr
On Wed, 19 Jun 2024 12:52:46 GMT, Alan Bateman wrote: >> @AlanBateman -- could you please take a look? Thanks. > >> @AlanBateman -- could you please take a look? Thanks. > > There was a lot of heap analysis done a few years ago that shined a light on > the number of empty collections in a typic

Re: RFR: 8332842: Optimize empty CopyOnWriteArrayList allocations [v3]

2024-06-20 Thread jengebr
On Thu, 6 Jun 2024 12:46:36 GMT, jengebr wrote: >> Improve `java/util/concurrent/CopyOnWriteArrayList` by eliminating needless >> cloning of Object[0] instances. This cloning is intended to prevent callers >> from changing array contents, but many `CopyOnWriteArrayList`s ar

Re: RFR: 8332842: Optimize empty CopyOnWriteArrayList allocations [v4]

2024-06-20 Thread jengebr
5 > 21.627 ± 0.173 ns/op > CopyOnWriteArrayListBenchmark.createInstanceCollectionEmpty avgt5 > 12.864 ± 0.408 ns/op > CopyOnWriteArrayListBenchmark.createInstanceDefault avgt5 > 12.931 ± 0.255 ns/op > CopyOnWriteArrayListBenchmark.readInstance avgt

Re: RFR: 8332842: Optimize empty CopyOnWriteArrayList allocations [v3]

2024-06-06 Thread jengebr
± 0.418 ns/op > CopyOnWriteArrayListBenchmark.createInstanceCollection avgt5 > 21.627 ± 0.173 ns/op > CopyOnWriteArrayListBenchmark.createInstanceCollectionEmpty avgt5 > 12.864 ± 0.408 ns/op > CopyOnWriteArrayListBenchmark.createInstanceDefault avgt5 > 12.9

Re: RFR: 8332842: Optimize empty CopyOnWriteArrayList allocations [v2]

2024-06-05 Thread jengebr
On Tue, 4 Jun 2024 19:58:41 GMT, jengebr wrote: >> Agreed. You might as well be consistent with this so that no one will need >> to re-address if some application does zillions of clones of empty lists. > > Sorry, I crossed wires with @DougLea 's comment, will add `clone`

Re: RFR: 8332842: Optimize empty CopyOnWriteArrayList allocations [v2]

2024-06-04 Thread jengebr
On Tue, 4 Jun 2024 19:41:15 GMT, Doug Lea wrote: >> src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java >> line 103: >> >>> 101: private static final long serialVersionUID = 8673264195747942595L; >>> 102: >>> 103: private static final Object[] EMPTY_ELEMENTDATA =

Re: RFR: 8332842: Optimize empty CopyOnWriteArrayList allocations [v2]

2024-06-04 Thread jengebr
± 0.418 ns/op > CopyOnWriteArrayListBenchmark.createInstanceCollection avgt5 > 21.627 ± 0.173 ns/op > CopyOnWriteArrayListBenchmark.createInstanceCollectionEmpty avgt5 > 12.864 ± 0.408 ns/op > CopyOnWriteArrayListBenchmark.createInstanceDefault avgt5 > 12.9

Re: RFR: 8332842: Optimize empty CopyOnWriteArrayList allocations

2024-06-04 Thread jengebr
On Mon, 3 Jun 2024 18:48:48 GMT, Doug Lea wrote: > The jmh benchmark checks only the empty case, you need to also show lack of > impact on non-empty cases. After removing `toArray`, I think this is covered. Can you please confirm? > Assuming you demonstrate this, it seems basically OK, (Deja

Re: RFR: 8332842: Optimize empty CopyOnWriteArrayList allocations

2024-06-03 Thread jengebr
On Mon, 3 Jun 2024 17:07:28 GMT, Aleksey Shipilev wrote: >> Improve `java/util/concurrent/CopyOnWriteArrayList` by eliminating needless >> cloning of Object[0] instances. This cloning is intended to prevent callers >> from changing array contents, but many `CopyOnWriteArrayList`s are allocated

RFR: 8332842: Optimize empty CopyOnWriteArrayList allocations

2024-06-03 Thread jengebr
Improve `java/util/concurrent/CopyOnWriteArrayList` by eliminating needless cloning of Object[0] instances. This cloning is intended to prevent callers from changing array contents, but many `CopyOnWriteArrayList`s are allocated to size zero, or are otherwise maintained empty, so cloning is unne

Integrated: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor}

2024-06-03 Thread jengebr
On Tue, 21 May 2024 13:49:18 GMT, jengebr wrote: > Improve `java/lang/reflect/Method.java` by eliminating needless cloning of > Class[0] instances. This cloning is intended to prevent callers from > changing array contents, but many Methods have zero exceptions or zero > par

Re: RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor} [v5]

2024-05-31 Thread jengebr
On Fri, 31 May 2024 17:59:18 GMT, jengebr wrote: >> Improve `java/lang/reflect/Method.java` by eliminating needless cloning of >> Class[0] instances. This cloning is intended to prevent callers from >> changing array contents, but many Methods have zero exceptions or zero

Re: RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor} [v6]

2024-05-31 Thread jengebr
2 ns/op > MethodBenchmark.getParameterTypesEmpty avgt5 1.273 ± 0.169 ns/op jengebr has updated the pull request incrementally with one additional commit since the last revision: Fixing nits in benchmark - Changes: - all: https://git.openjdk.org/jdk/pull/19327/files

Re: RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor} [v5]

2024-05-31 Thread jengebr
2 ns/op > MethodBenchmark.getParameterTypesEmpty avgt5 1.273 ± 0.169 ns/op jengebr has updated the pull request incrementally with one additional commit since the last revision: Fixing copyright message, returning values from benchmark - Changes: - all: https://

Re: RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor} [v4]

2024-05-31 Thread jengebr
2 ns/op > MethodBenchmark.getParameterTypesEmpty avgt5 1.273 ± 0.169 ns/op jengebr has updated the pull request incrementally with one additional commit since the last revision: rewriting JMH per comments - Changes: - all: https://git.openjdk.org/jdk/pull/19327/files

Re: RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor} [v3]

2024-05-31 Thread jengebr
On Fri, 31 May 2024 16:53:36 GMT, jengebr wrote: >> Improve `java/lang/reflect/Method.java` by eliminating needless cloning of >> Class[0] instances. This cloning is intended to prevent callers from >> changing array contents, but many Methods have zero exceptions or zero

Re: RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor} [v3]

2024-05-31 Thread jengebr
s sufficient. jengebr has updated the pull request incrementally with one additional commit since the last revision: Correcting and renaming benchmark - Changes: - all: https://git.openjdk.org/jdk/pull/19327/files - new: https://git.openjdk.org/jdk/pull/19327/files/4865dede..31b64

Re: RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor}

2024-05-31 Thread jengebr
exceptions or zero >> parameters, and returning the original `Class[0]` is sufficient. > > Please also enable GHA testing: https://github.com/jengebr/jdk/actions. You > may need to trigger the test run manually after this, since the PR hook have > already missed it. Go to "OpenJD

Re: RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor} [v2]

2024-05-31 Thread jengebr
s sufficient. jengebr has updated the pull request incrementally with one additional commit since the last revision: Adding JMH benchmark - Changes: - all: https://git.openjdk.org/jdk/pull/19327/files - new: https://git.openjdk.org/jdk/pull/19327/files/3202c8cb..4865dede Webr

Re: RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor}

2024-05-30 Thread jengebr
On Wed, 22 May 2024 13:44:59 GMT, Chen Liang wrote: >> @liach I see such an opportunity in `Proxy.getProxyConstructor`, is that >> what you have in mind? > > No, I mean here: > https://github.com/openjdk/jdk/blob/4f1a10f84bcfadef263a0890b6834ccd3d5bb52f/src/java.base/share/classes/java/lang/Cla

Re: RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor}

2024-05-30 Thread jengebr
On Thu, 23 May 2024 09:05:09 GMT, Aleksey Shipilev wrote: >> Alternatively, if a utility method is overkill, we can inline these to >> `Executable`: >> >> public Class[] getParameterTypes() { >> var shared = getSharedParameterTypes(); >> return shared.length == 0 ? shared : shared.clone

Re: RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor}

2024-05-30 Thread jengebr
On Wed, 22 May 2024 10:27:16 GMT, Chen Liang wrote: >> src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java line >> 249: >> >>> 247: * the original can safely be reused. >>> 248: */ >>> 249: public Class[] copyClasses(Class[] classes) { >> >> There is no need t

Re: RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor}

2024-05-30 Thread jengebr
On Fri, 24 May 2024 21:59:58 GMT, Chen Liang wrote: > Can you update the ending copyright years from 2023 to 2024 on the 2nd line > of the 2 modified files? Done, thank you. - PR Comment: https://git.openjdk.org/jdk/pull/19327#issuecomment-2135215681

Re: RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor}

2024-05-30 Thread jengebr
On Wed, 22 May 2024 09:44:18 GMT, Aleksey Shipilev wrote: > Please also enable GHA testing: https://github.com/jengebr/jdk/actions. You > may need to trigger the test run manually after this, since the PR hook have > already missed it. Go to "OpenJDK Sanity Checks" on th

RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor}

2024-05-30 Thread jengebr
Improve `java/lang/reflect/Method.java` by eliminating needless cloning of Class[0] instances. This cloning is intended to prevent callers from changing array contents, but smany Methods have zero exceptions or zero parameters, and returning the original `Class[0]` is sufficient.

Re: RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor}

2024-05-30 Thread jengebr
On Tue, 21 May 2024 13:49:18 GMT, jengebr wrote: > Improve `java/lang/reflect/Method.java` by eliminating needless cloning of > Class[0] instances. This cloning is intended to prevent callers from > changing array contents, but smany Methods have zero exceptions or zero > par