-
Notifications
You must be signed in to change notification settings - Fork 368
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
Const data class #51
base: master
Are you sure you want to change the base?
Const data class #51
Conversation
Please redo the benchmarking using JMH. It is very hard to reason about the correctness of your current benchmark: maybe you forgot a tiny detail which changes everything, maybe you didn't. Only a dev of level "hotspot jvm maintainer" could tell the difference ;) |
Another alternative: Change the algorithm for all
Then implements a hashing function with hashing |
This proposal seems to be also applicable to |
About the alternative to implement A compiler-implemented annotation has an ability to check its applicant in detail. For instance it can check that the class is |
How it will works with serialization? I see possible problems of transferring hashCode between JVMs. |
You're right. All cached values should be |
@SalomonBrys JMH is the recommended way of benchmarking in JVM. http://openjdk.java.net/projects/code-tools/jmh/ |
@SalomonBrys auto detection will be inconsistent with the rest of Kotlin because it silently adds a field to a class. That may be critical when you optimize for small footprint. |
What is the reasoning for making the cache @volatile? |
@voddan, You're right. I've moved the auto-detection paragraph to the "alternatives" section, and annotated it with your reserve. The cached values should be volatile because multiple threads may access I'll update the benchmark using JVMH next week, when I'll have access to my linux PC ;) |
What corruption may that cause? The hash is an This is important because volatile reads may have a significant overhead http://stackoverflow.com/a/12357342/3144601 |
It's corner case, but on my jvm for 4294967297 number hashCode is 0, so your code will compute it every time) |
|
Proposal
Proposition:
const data class
would enable immutability guarantee of both structure and values of data classes, thus enabling cached hash code, which divides read time inHashSet
/HashMap
by 3.