Skip to content
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

Closed
wants to merge 13 commits into from

Conversation

ingvard
Copy link
Contributor

@ingvard ingvard commented May 14, 2019

No description provided.

}
else
return false;
return bitSet.nextSetBit(idx + 1) != -1;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

* @param key Targert key.
*/
protected int index(int key) {
return (entries.length - 1) & (key ^ (key >>> 16));
Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please nooo.

# 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
@asfgit asfgit closed this in 4eda065 Aug 11, 2019
glukos pushed a commit to gridgain/apache-ignite that referenced this pull request Aug 12, 2019
glukos pushed a commit to gridgain/apache-ignite that referenced this pull request Aug 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants