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
IGNITE-6957 Boxing / Unboxing optimization - added IntSet. #6536
Conversation
...e/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentV2.java
Outdated
Show resolved
Hide resolved
...e/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentV2.java
Outdated
Show resolved
Hide resolved
modules/core/src/main/java/org/apache/ignite/internal/util/collection/BitSetIntSet.java
Outdated
Show resolved
Hide resolved
modules/core/src/main/java/org/apache/ignite/internal/util/collection/BitSetIntSet.java
Show resolved
Hide resolved
} | ||
else | ||
return false; | ||
return bitSet.nextSetBit(idx + 1) != -1; |
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 suggest the optimization: store nextIdx in field after calculation. We can easily support following invariant:
- idx == nextIdx - "hasNext" hasn't been invoked or set is empty.
- idx != nextIdx - "hasNext" has been invoked and set is not empty, "next" has not been invoked (each "next" invocation will execute "nextIdx = idx = nextIdx").
What do you think? It'll reduce number of array scans to 1 instead of 2.
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.
Fixed
modules/core/src/main/java/org/apache/ignite/internal/util/collection/IntHashMap.java
Outdated
Show resolved
Hide resolved
modules/core/src/main/java/org/apache/ignite/internal/util/collection/IntHashMap.java
Outdated
Show resolved
Hide resolved
modules/core/src/main/java/org/apache/ignite/internal/util/collection/IntHashMap.java
Outdated
Show resolved
Hide resolved
modules/core/src/main/java/org/apache/ignite/internal/util/collection/IntHashMap.java
Outdated
Show resolved
Hide resolved
modules/core/src/main/java/org/apache/ignite/internal/util/collection/IntHashMap.java
Outdated
Show resolved
Hide resolved
* @param key Targert key. | ||
*/ | ||
protected int index(int key) { | ||
return (entries.length - 1) & (key ^ (key >>> 16)); |
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 can use better hash function here and cache this value in methods whenever it's possible.
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.
fixed
protected int distance(int curIdx, int key) { | ||
int keyIdx = index(key); | ||
|
||
return curIdx >= keyIdx ? curIdx - keyIdx : entries.length - keyIdx + curIdx; |
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.
"curIdx >= keyIdx" uses subtraction implicitly, so you make it twice.
"curIdx - keyIdx" can be calculated a line before, comparing it to zero will be "much faster".
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.
please nooo.
modules/core/src/main/java/org/apache/ignite/internal/util/collection/IntHashMap.java
Outdated
Show resolved
Hide resolved
...es/core/src/test/java/org/apache/ignite/internal/util/collection/AbstractBaseIntMapTest.java
Show resolved
Hide resolved
modules/core/src/test/java/org/apache/ignite/internal/util/collection/IntHashMapTest.java
Outdated
Show resolved
Hide resolved
# Conflicts: # modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java # modules/core/src/test/java/org/apache/ignite/internal/util/collection/BitSetIntSetTest.java
…accessing cache by ID - Fixes apache#6536.
…accessing cache by ID - Fixes apache#6536.
No description provided.