RFR: 8332249: Micro-optimize Method.hashCode [v2]
Chen Liang
liach at openjdk.org
Thu Jun 6 11:46:46 UTC 2024
On Thu, 6 Jun 2024 06:41:48 GMT, ExE Boss <duke at openjdk.org> wrote:
>> Sean Gwizdak has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains six additional commits since the last revision:
>>
>> - Remove trailing whitespace.
>> - Move hashCode benchmark into the newly created MethodBenchmark file
>> - Merge branch 'master' into method-hashcode-JDK-8332249
>> - Remove changes to JavaDoc per guidance.
>> - Fix whitespace issues pointed by the bot
>> - Micro-optimize Method.hashCode
>
> src/java.base/share/classes/java/lang/reflect/Method.java line 392:
>
>> 390: .hashCode();
>> 391: }
>> 392: return hc;
>
> The `hash` field should probably somehow be shared with the `Method.root` instance, so that it doesn’t need to be recomputed when different code gets a `Method` reference.
Currently the hashCode computation is quite cheap. I think we can consider this delegation if it gets more complex, say if the hash code now considers parameters.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/19433#discussion_r1629365372
More information about the core-libs-dev
mailing list