Skip to content

Work around slow PriorityQueue.remove - #2092

Merged
karussell merged 5 commits into
masterfrom
faster_spt
Jul 24, 2020
Merged

karussell merged 5 commits into
masterfrom
faster_spt

Conversation

@michaz

@michaz michaz commented Jul 22, 2020

Copy link
Copy Markdown
Member

See #2086.

@michaz
michaz requested a review from karussell July 22, 2020 16:31
}
}

private IntHashSet queueDeleted = new IntHashSet();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this used?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No.

queueByZ.poll();
if (queueByZ.peek() == null)
return true;
return getExploreValue(queueByZ.peek()) >= limit;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

while (!queueByZ.isEmpty()) {
    IsoLabel head = queueByZ.poll();
    if (!head.deleted) {
        return getExploreValue(head) >= limit;
    }
}
return true;

Depending on the size of the underlying array it would probably be faster to sort it once and iterate over the array.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The Java PriorityQueue is an extreme fast implementation (also backed on an array) and so it is incredible hard to beat it even if alternatives are theoretically faster.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would also allow to use a more finegrained Comparator and sort by deleted+z

@karussell karussell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice idea and works for me!

I'm just in the process to create a PR which adds isochrone to the measurement and would like to merge it before this PR so we should be able to see the differences better.

queueByZ.poll();
if (queueByZ.peek() == null)
return true;
return getExploreValue(queueByZ.peek()) >= limit;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The Java PriorityQueue is an extreme fast implementation (also backed on an array) and so it is incredible hard to beat it even if alternatives are theoretically faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants