Repository navigation
use staticHashCode to fix problems on Android but could occur elsewhere - #1660
Conversation
| if (vals == null) | ||
| return 0; | ||
| int len = vals.length; | ||
| Enum[] locVal = vals; |
There was a problem hiding this comment.
very minor, but do we really need the extra locVal reference or can we not just do vals[idx] in the loop below ?
There was a problem hiding this comment.
I read somewhere (cannot find the link now) that a local variable can have different behaviour (faster). When thinking where this can come for one explanation would make sense if you assign an instance variable to a local variable (moving it from heap to stack). But here it is basically a method parameter (stack) to stack. There must be a reason as this is done e.g. in Arrays#hashCode. But obviously the stack allocation has to be larger and also more bytecode lines are produced (checked via javap -v) and some say they are identical. Will remove it and read a bit more about the JVM internals.
There was a problem hiding this comment.
Will remove it and read a bit more about the JVM internals.
Cool looking forward to hear what you find out.
There was a problem hiding this comment.
Haven't found much. Just tested it in JMH and it looks that between arrays as parameter or local variable there is no difference, but as a class variable the code is indeed ~5% slower:
(Obviously this tuning only makes sense if you have millions of iterations)
|
Not sure if this is relevant here, but in another project I once ran into a performance problem, because |
|
Apparently this was also a problem under mac OS |
Yeah. It is kind of ugly that this is now the default for IntelliJ as hashing should be very fast and lightweight |
Fixes #1650