Skip to content

use staticHashCode to fix problems on Android but could occur elsewhere - #1660

Merged
karussell merged 2 commits into
masterfrom
issue_1650
Jul 19, 2019
Merged

karussell merged 2 commits into
masterfrom
issue_1650

Conversation

@karussell

Copy link
Copy Markdown
Member

Fixes #1650

@karussell karussell added the bug label Jul 10, 2019
@karussell karussell added this to the 0.13 milestone Jul 10, 2019
@karussell
karussell merged commit 2a971fc into master Jul 19, 2019
@karussell
karussell deleted the issue_1650 branch July 19, 2019 11:06
if (vals == null)
return 0;
int len = vals.length;
Enum[] locVal = vals;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very minor, but do we really need the extra locVal reference or can we not just do vals[idx] in the loop below ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove it and read a bit more about the JVM internals.

Cool looking forward to hear what you find out.

@karussell karussell Jul 24, 2019 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

https://gist.github.com/karussell/4cd7999235c651f7e714630b61297c6b

(Obviously this tuning only makes sense if you have millions of iterations)

@easbar

easbar commented Jul 19, 2019

Copy link
Copy Markdown
Member

Not sure if this is relevant here, but in another project I once ran into a performance problem, because Objects.hash(Object...) was creating lots of temporary Object[] instances.

@easbar

easbar commented Jul 19, 2019

Copy link
Copy Markdown
Member

Apparently this was also a problem under mac OS

@karussell

Copy link
Copy Markdown
Member Author

but in another project I once ran into a performance problem, because Objects.hash(Object...)

Yeah. It is kind of ugly that this is now the default for IntelliJ as hashing should be very fast and lightweight

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot load graph on Android due to mismatching version for road_class EncodedValue

2 participants