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

memoize hashCode #210

Closed
davidmarne opened this issue Aug 27, 2017 · 1 comment
Closed

memoize hashCode #210

davidmarne opened this issue Aug 27, 2017 · 1 comment
Assignees

Comments

@davidmarne
Copy link

It would make sense to memoize the result of hashCode like you do in built_collection.

Is there any reason you do not? Would the performance gains be negligible? I'm not sure how expensive those bit-wise operations are in dart but it seems like it would be work memoizing, especially when using built_value with dart2js.

@davidmorgan
Copy link
Collaborator

Well, we'd have to measure to know the performance gains :) ... if you have a particular case in mind you could hack the .g.dart files yourself and try it.

You'd save the most time where you're using built_value for a large structure that does not rely on built_collection; for example if you're build a tree out of built_value Nodes. But, you'd also pay a lot for memory use.

The way Guava's @AutoValue does this is to allow you to redeclare hashCode as abstract then annotate to make it memoized.

https://github.com/google/auto/blob/master/value/src/main/java/com/google/auto/value/extension/memoized/Memoized.java

Then you can decide for yourself. How does that sound?

I was already planning on adding this at some point.

Related: when using both on the server and the client, it might make sense to calculate the hashCode server side and serialize it: #195

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

No branches or pull requests

2 participants