-
Notifications
You must be signed in to change notification settings - Fork 851
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
Optimize map accesses in several places #1644
Conversation
5616739
to
972f5e2
Compare
// Update the existing value and keep it in the same place in the list | ||
map.get(nv).value = value; | ||
} | ||
map.compute( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will save one hash computation, but have the price of an additional invocation of a lambda expression:
I did this short test:
@Test
public void speed() {
for (long i = 0L; i < 10_000_000L; i++) {
ht.put("one", 1);
ht.put("two", 2);
ht.put("three", 3);
ht.put("four", 4);
ht.put("five", 5);
ht.put("six", 6);
ht.put("seven", 7);
ht.put("eight", 8);
ht.put("nine", 9);
ht.put("ten", 10);
}
}
it runs with the old code in apporx 8,5sec and with the new code approx 5,5 sec
@@ -595,23 +599,21 @@ private void reflect( | |||
NativeJavaMethod setters = null; | |||
String setterName = "set".concat(nameComponent); | |||
|
|||
if (ht.containsKey(setterName)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can safely remove containsKey
here, as we call get
in the next line, which is checked for null by the instanceOf
test.
@@ -687,13 +689,11 @@ private Field[] getAccessibleFields(boolean includeProtected, boolean includePri | |||
private static MemberBox findGetter( | |||
boolean isStatic, Map<String, Object> ht, String prefix, String propertyName) { | |||
String getterName = prefix.concat(propertyName); | |||
if (ht.containsKey(getterName)) { | |||
// Check that the getter is a method. | |||
Object member = ht.get(getterName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here. Do not hit map twice
Yes, this is a good change. Thanks! |
In this PR I will try to optimize map access on several places and pick up @gbrail's comment: #1575 (comment)