Skip to content

[GR-37191] Record equals/hashCode use reflection #4348

Closed
@TheMode

Description

@TheMode

Describe the issue
Record equals (and I assume hashCode, even if untested) currently use reflection, and effectively run much slower (about x10-20 in my case compared to my specialized method comparing the fields directly)

Describe GraalVM and your environment:

  • GraalVM 22.0.0.2
  • JDK major version: 17
  • OS: Linux/PopOS
  • Architecture:AMD64

More details
I have noticed the issue due to a hot path in my code being weirdly expensive:
https://github.com/Minestom/Minestom/blob/2c0b026e46f271a88cd9824e00f211c25980a7f1/src/main/java/net/minestom/server/listener/PlayerPositionListener.java#L36
https://github.com/Minestom/Minestom/blob/2c0b026e46f271a88cd9824e00f211c25980a7f1/src/main/java/net/minestom/server/entity/Entity.java#L1239
(notice the Pos#equals calls)

Flamegraph obtained with perf: flamegraph

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions