Skip to content

Caching of Hashcode in generated objects #233

@jasperpotts

Description

@jasperpotts

Problem

Computing the hashcode over and over is a performance problem. Specifically with the extra shifts to randomize that is done for better bucket distribution when objects are used as map keys.

Solution

Move all PBJ model objects from Java Record to final Java Classes. Implement code generation for constructors, fields, getter methods and toString() method. Then add a private hashCode field that is computed at construction time and caches the hashCode as it is constant as objects are immutable. We should also use the new computed cached hashCode in the equals() method to fail fast if the hashCodes do not match.

Alternatives

No response

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions