Skip to content

Commit

Permalink
Improve GroupBy query performance by setting initial size for OpenHas…
Browse files Browse the repository at this point in the history
…hMap used in DictionaryBasedGroupKeyGenerator.
  • Loading branch information
xiangfu0 committed Apr 23, 2020
1 parent e604468 commit 0bb8d7b
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ public DictionaryBasedGroupKeyGenerator(TransformOperator transformOperator,

if (longOverflow) {
_globalGroupIdUpperBound = numGroupsLimit;
_rawKeyHolder = new ArrayMapBasedHolder();
_rawKeyHolder = new ArrayMapBasedHolder(_globalGroupIdUpperBound);
} else {
if (cardinalityProduct > Integer.MAX_VALUE) {
_globalGroupIdUpperBound = numGroupsLimit;
_rawKeyHolder = new LongMapBasedHolder();
_rawKeyHolder = new LongMapBasedHolder(_globalGroupIdUpperBound);
} else {
_globalGroupIdUpperBound = Math.min((int) cardinalityProduct, numGroupsLimit);
if (cardinalityProduct > arrayBasedThreshold) {
_rawKeyHolder = new IntMapBasedHolder();
_rawKeyHolder = new IntMapBasedHolder(_globalGroupIdUpperBound);
} else {
_rawKeyHolder = new ArrayBasedHolder();
}
Expand Down Expand Up @@ -259,11 +259,12 @@ public void remove() {
}

private class IntMapBasedHolder implements RawKeyHolder {
private final Int2IntOpenHashMap _rawKeyToGroupIdMap = new Int2IntOpenHashMap();
private final Int2IntOpenHashMap _rawKeyToGroupIdMap;

private int _numGroups = 0;

public IntMapBasedHolder() {
public IntMapBasedHolder(int initialSize) {
_rawKeyToGroupIdMap = new Int2IntOpenHashMap(initialSize);
_rawKeyToGroupIdMap.defaultReturnValue(INVALID_ID);
}

Expand Down Expand Up @@ -437,11 +438,12 @@ private String getGroupKey(int rawKey) {
}

private class LongMapBasedHolder implements RawKeyHolder {
private final Long2IntOpenHashMap _rawKeyToGroupIdMap = new Long2IntOpenHashMap();
private final Long2IntOpenHashMap _rawKeyToGroupIdMap;

private int _numGroups = 0;

public LongMapBasedHolder() {
public LongMapBasedHolder(int initialSize) {
_rawKeyToGroupIdMap = new Long2IntOpenHashMap(initialSize);
_rawKeyToGroupIdMap.defaultReturnValue(INVALID_ID);
}

Expand Down Expand Up @@ -607,11 +609,12 @@ private String getGroupKey(long rawKey) {
}

private class ArrayMapBasedHolder implements RawKeyHolder {
private final Object2IntOpenHashMap<IntArray> _rawKeyToGroupIdMap = new Object2IntOpenHashMap<>();
private final Object2IntOpenHashMap<IntArray> _rawKeyToGroupIdMap;

private int _numGroups = 0;

public ArrayMapBasedHolder() {
public ArrayMapBasedHolder(int initialSize) {
_rawKeyToGroupIdMap = new Object2IntOpenHashMap<>(initialSize);
_rawKeyToGroupIdMap.defaultReturnValue(INVALID_ID);
}

Expand Down

0 comments on commit 0bb8d7b

Please sign in to comment.