RFR: 8306075: Micro-optimize Enum.hashCode [v6]
Jorn Vernee
jvernee at openjdk.org
Fri Apr 21 03:42:56 UTC 2023
On Mon, 17 Apr 2023 16:42:38 GMT, olivergillespie <duke at openjdk.org> wrote:
>> Improve the speed of Enum.hashCode by caching the identity hashcode on first use. I've seen an application where Enum.hashCode is a hot path, and this is fairly simple speedup. The memory overhead is low; in enums with no extra fields there is already a 4-byte space due to alignment so this new field can slot in 'for free'. In other cases, the singleton nature of enum values means that the number of total instances is typically very low, so a small per-instance overhead is not a concern.
>>
>> Please see more discussion/explanation in the [original enhancement request](https://bugs.openjdk.org/browse/JDK-8306075). [Benchmark results and generated code analysis moved to comment]
>>
>> Thanks @shipilev for help with the implementation and interpreting the generated code.
>
> olivergillespie has updated the pull request incrementally with one additional commit since the last revision:
>
> Shuffle docs
> I've also started a tier 1-4 run of this patch on our CI. Will report back with the results.
All green
-------------
Marked as reviewed by jvernee (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/13491#pullrequestreview-1395011994
More information about the core-libs-dev
mailing list