Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching of Hashcode in generated objects #233

Open
jasperpotts opened this issue Mar 12, 2024 · 0 comments
Open

Caching of Hashcode in generated objects #233

jasperpotts opened this issue Mar 12, 2024 · 0 comments

Comments

@jasperpotts
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant