You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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
The text was updated successfully, but these errors were encountered: