On Mon, 17 Apr 2023 10:59:34 GMT, olivergillespie <d...@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. This pull request has now been integrated. Changeset: 3da987ad Author: Oli Gillespie <ogill...@amazon.com> Committer: Aleksey Shipilev <sh...@openjdk.org> URL: https://git.openjdk.org/jdk/commit/3da987adacc3acc120a2781ee9a2111e26356723 Stats: 73 lines in 2 files changed: 72 ins; 0 del; 1 mod 8306075: Micro-optimize Enum.hashCode Co-authored-by: Aleksey Shipilev <sh...@openjdk.org> Reviewed-by: redestad, shade, rriggs, liach, apangin, jvernee ------------- PR: https://git.openjdk.org/jdk/pull/13491