[Jts-topo-suite-user] Geometry.equals(Object) performance optimization
Brought to you by:
dr_jts
From: Nathan J. <ndj...@gm...> - 2014-11-18 21:54:07
|
Hi, I've noticed in the newer versions of JTS that Geometry.equals(Object) calls into Geometry.equalsExact(other) which then goes into the subclasses to determine equality based on a tolerance. It appears that all identity checking has been removed from equals(Object) but you could speed up the check with a simple check for reference equality. Specifically, a one line change to Geometry.equalsExact(other) like this: public boolean equalsExact(Geometry other) { return this == other || equalsExact(other, 0); } will return quicker and save you the trouble of calculating equalsExact with the tolerance if you are comparing the exact same object in memory. This has performance implications beyonds just equals() calls. I traced this down while investigating Geotools' PolygonHandler.assignHolesToShells() because the ArrayList.indexOf(LinearRing) was slow and would compare the equalsExact even when it had the exact same object. This slight enhancement only saves time when you do encounter the exact same reference, but in those cases it can save a measurable amount of time. Please consider this slight optimization for a future release of JTS. |