-
Notifications
You must be signed in to change notification settings - Fork 14
Caching of Hashcode in generated objects #233
Copy link
Copy link
Closed
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels