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

Improve performance of UniqueCoordinateFilter #422

Merged
merged 3 commits into from
Apr 26, 2019

Conversation

dr-jts
Copy link
Contributor

@dr-jts dr-jts commented Apr 25, 2019

Use HashSet, and boolean return value from Set.add().
Javadoc improvements

Based on suggestions in #420.

TreeSet treeSet = new TreeSet();
ArrayList list = new ArrayList();
private Set<Coordinate> coordSet = new HashSet<Coordinate>();
// Use an auxiliary list as well in order to preserve coordinate order
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder about LinkedHashSet here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting suggestion. But I suspect that using an ArrayList is more efficient, since it is simpler than a doubly linked list?

LinkedHashSet is probably better for situations where the ordering needs to be maintained dymamically, whereas in this use case requires only a single access to the ordered points.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I can imagine the ArrayList coming out ahead too. Hard to say without measuring. Just thought I'd mention it in case it hadn't occurred to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks... good to be reminded of the ever-increasing plethora of useful Java data structures.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right that the ArrayList is faster. Filtering a million-coordinate array ten times takes 12.1s in master, 2.5s with this PR, and 2.8s with the LinkedHashSet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice! The big win of course is the improvement over master. But the extra few cycles saved with ArrayLIst are nice too.

@dr-jts dr-jts merged commit 5e01aea into locationtech:master Apr 26, 2019
@dr-jts dr-jts deleted the improve-uniquecoordfilter branch April 26, 2019 22:06
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.

2 participants