Skip to content

Commit

Permalink
Do not store distinct elements when single iterator processed
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Ershov <[email protected]>
  • Loading branch information
mad authored and FlorianHockmann committed Dec 7, 2022
1 parent 14ef94d commit 91308f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ public class MultiDistinctOrderedIterator<E extends Element> implements Closeabl
private final TreeMap<E, Integer> currentElements;
private final Set<Object> allElements = new HashSet<>();
private final Integer limit;
private final boolean singleIterator;
private long count = 0;

public MultiDistinctOrderedIterator(final Integer lowLimit, final Integer highLimit, final List<Iterator<E>> iterators, final List<OrderEntry> orders) {
this.limit = highLimit;
this.singleIterator = iterators.size() == 1;
final List<Comparator<E>> comp = new ArrayList<>();
orders.forEach(o -> comp.add(new ElementValueComparator(o.key, o.order)));
Comparator<E> comparator = new MultiComparator<>(comp);
Expand Down Expand Up @@ -73,7 +75,9 @@ public boolean hasNext() {
if (element != null) {
values.put(i, element);
currentElements.put(element, i);
allElements.add(element.id());
if (!singleIterator) {
allElements.add(element.id());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public class MultiDistinctUnorderedIterator<E extends Element> extends Closeable
private final Set<Object> allElements = new HashSet<>();
private final CloseableIterator<E> iterator;
private final int limit;
private final boolean singleIterator;
private long count;

public MultiDistinctUnorderedIterator(final int lowLimit, final int highLimit, final List<Iterator<E>> iterators) {
Objects.requireNonNull(iterators);
iterator = CloseableIteratorUtils.concat(iterators);
limit = highLimit;
singleIterator = iterators.size() == 1;

long i = 0;
while (i < lowLimit && hasNext()) {
Expand All @@ -47,7 +49,7 @@ protected E computeNext() {
if (count < limit) {
while (iterator.hasNext()) {
E elem = iterator.next();
if (allElements.add(elem.id())) {
if (singleIterator || allElements.add(elem.id())) {
count++;
return elem;
}
Expand Down

1 comment on commit 91308f6

@github-actions
Copy link

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 91308f6 Previous: 497fd97 Ratio
org.janusgraph.MgmtOlapJobBenchmark.runRemoveIndex 115.71672427811839 ms/op 114.55075151272729 ms/op 1.01
org.janusgraph.JanusGraphSpeedBenchmark.basicAddAndDelete 17362.508382011256 ms/op 14638.489043599999 ms/op 1.19
org.janusgraph.GraphCentricQueryBenchmark.getVertices 1495.954459113028 ms/op 1771.8561209198785 ms/op 0.84
org.janusgraph.MgmtOlapJobBenchmark.runReindex 422.8278594384616 ms/op 355.1724081138462 ms/op 1.19
org.janusgraph.JanusGraphSpeedBenchmark.basicCount 489.8570207782229 ms/op 320.9125319386942 ms/op 1.53
org.janusgraph.CQLMultiQueryBenchmark.getNeighborNames 45153.22878255 ms/op 43280.721668460006 ms/op 1.04
org.janusgraph.CQLMultiQueryBenchmark.getNames 45346.6503909 ms/op 42562.844616426664 ms/op 1.07

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.