[geos-devel] JTS/GEOS performance

Martin Davis mbdavis at VividSolutions.com
Wed Feb 2 12:17:35 EST 2005

> My proposal is to make GEOS interfaces closer to JTS in using 
> vectors of Coordinates wherever JTS uses Coordinate[]. 

In actual fact, the use of CoordinateSequence in GEOS was completely
deliberate, and I intend to migrate JTS to use that pattern as well.
The reason was to encapsulate the representation of coordinate values,
to easily allow using alternative coordinates and coordinate list
implementations with JTS/GEOS.

There may be a performance penalty to be paid for this flexibility, but
I (and others) think that the increased versatility and cleaner
architecture.  In fact, I would expect that with C++'s much better
optimization and richer language model the penalty (if any) should be
much less than in Java.  

Since CoordinateSequence::getAt() returns a reference, I don't see why
that would be much slower than simply dereferencing an array.

> I'd consider using vector<Coordinate>, which can returned 
> with no copy involved by the DefaultCoordinateSequence using 
> the toVector() method.

Could this be the source of the problem?  JTS uses getCoordinates all
over the place.  This is NOT going to be efficient under the new
CoordinateSequence pattern, since it requires converting a
CoordinateSequence into a Coordinate[].  Instead, the JTS code will have
to be rewritten to use a getCoordinate(int, Coordinate) method, which
will extract the coordinate value into a provided Coordinate object.
This lets the caller manage the memory (and in most cases, very few
actual Coordinate objects have to be allocated).  I suspect that GEOS,
although partially implemented using the CoordinateSequence pattern, was
not fully converted to this pattern (fair enough, since this is a major
change to the code and a major departure from alignment with JTS).
Strk, can you confirm this assumption?

So there's 2 choices - alter GEOS now, or wait until JTS moves and then
mirror it.  

Martin Davis, Senior Technical Architect
Vivid Solutions Inc.      www.vividsolutions.com
Suite #1A-2328 Government Street Victoria, B.C. V8T 5G5
Phone: (250) 385 6040 - Local 308 Fax: (250) 385 6046

More information about the geos-devel mailing list