Avoid Coordinate allocations in Area and Length sequence computations#1211
Open
nishantmehta wants to merge 1 commit into
Open
Avoid Coordinate allocations in Area and Length sequence computations#1211nishantmehta wants to merge 1 commit into
nishantmehta wants to merge 1 commit into
Conversation
Area.ofRingSigned(CoordinateSequence) and Length.ofLine(CoordinateSequence) allocated Coordinate objects (three and one respectively) per call via CoordinateSequence.createCoordinate(), purely to read x/y values while iterating. These back Geometry.getArea() and getLength(), which are commonly called in hot paths. Read coordinates through the primitive CoordinateSequence.getX(int)/getY(int) accessors instead. The arithmetic is unchanged (Area still uses the Shoelace formula, caching the y values so each is read once; Length still sums segment hypotenuses), and no Coordinate instances are created. Measured with a ThreadMXBean allocation driver (200k warmed ops): Geometry.getArea 28.5 -> 0 B/op, Geometry.getLength 40 -> 0 B/op. The full jts-core test suite (2294 tests) passes unchanged. Signed-off-by: Nishant Mehta <nishantmehta.n@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Area.ofRingSigned(CoordinateSequence)andLength.ofLine(CoordinateSequence)allocatedCoordinateobjects (three and one respectively) per call viaCoordinateSequence.createCoordinate(), purely to read x/y values while iterating. These backGeometry.getArea()andgetLength(), which are commonly called in hot paths.This reads coordinates through the primitive
CoordinateSequence.getX(int)/getY(int)accessors instead. The arithmetic is unchanged —Areastill uses the Shoelace formula (caching the y values so each is read once), andLengthstill sums segment hypotenuses — and noCoordinateinstances are created.Benchmark
Measured with a
ThreadMXBeanallocation driver (200k warmed ops):Testing
The full
jts-coretest suite (2294 tests) passes unchanged.