Skip to content

Conversation

@jush
Copy link
Member

@jush jush commented Jan 26, 2026

The main difference is the introduction of FlattenListOfPoints which is able to store a list of coordinate points (latitude, longitude, altitude, bounding box) as a collection of arrays.

Also avoid using List<Point> and instead use double [] to avoid extra memory use.

This change improves memory usage significantly:

Before: using List After: using double []
3M points LineString take 286,1MB 3M points LineString take 45,8MB
non-optimized-list-points optimized-list-points

It also unlocks the possibility to use JNI#GetArrayElements to access the array in one JNI call.

I have deprecated the LineString#coordinates() and Point#coordinates(). They can still be used but let's encourage the use of the flat structure or direct calls to longitude(), latitude(), altitude() in case of Point.

To avoid breaking things a new interface FlattenedCoordinateContainer is added to support the new flattenCoordinates() method used in serialization code that inherits from the already existing CoordinateContainer.
BaseGeometryTypeAdapter is modified to support this new container (method writeFlattenedCoordinateContainer()).

Also the unit tests are extended to cover the new logic plus improve older tests.

@codecov
Copy link

codecov bot commented Jan 29, 2026

Codecov Report

❌ Patch coverage is 81.87500% with 58 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.19%. Comparing base (5eddaf6) to head (164c42d).

Files with missing lines Patch % Lines
...n/src/main/java/com/mapbox/geojson/LineString.java 64.86% 7 Missing and 6 partials ⚠️
...mapbox/geojson/FlattenListOfPointsTypeAdapter.java 83.07% 6 Missing and 5 partials ⚠️
...com/mapbox/geojson/BaseCoordinatesTypeAdapter.java 54.54% 7 Missing and 3 partials ⚠️
...eojson/src/main/java/com/mapbox/geojson/Point.java 64.00% 4 Missing and 5 partials ⚠️
...va/com/mapbox/geojson/BaseGeometryTypeAdapter.java 65.00% 4 Missing and 3 partials ⚠️
...n/src/main/java/com/mapbox/geojson/MultiPoint.java 58.82% 2 Missing and 5 partials ⚠️
...n/java/com/mapbox/geojson/FlattenListOfPoints.java 98.79% 0 Missing and 1 partial ⚠️

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1630      +/-   ##
============================================
+ Coverage     78.08%   79.19%   +1.11%     
- Complexity     1070     1128      +58     
============================================
  Files           161      162       +1     
  Lines          4508     4697     +189     
  Branches        626      660      +34     
============================================
+ Hits           3520     3720     +200     
+ Misses          719      707      -12     
- Partials        269      270       +1     
Files with missing lines Coverage Δ
...x/geojson/ListOfDoublesCoordinatesTypeAdapter.java 100.00% <100.00%> (ø)
.../main/java/com/mapbox/geojson/MultiLineString.java 57.74% <ø> (ø)
...src/main/java/com/mapbox/geojson/MultiPolygon.java 55.40% <ø> (ø)
...json/src/main/java/com/mapbox/geojson/Polygon.java 73.07% <ø> (ø)
...pbox/geojson/shifter/CoordinateShifterManager.java 100.00% <100.00%> (+15.38%) ⬆️
...n/java/com/mapbox/geojson/utils/PolylineUtils.java 84.86% <100.00%> (+6.36%) ⬆️
...n/java/com/mapbox/geojson/FlattenListOfPoints.java 98.79% <98.79%> (ø)
...va/com/mapbox/geojson/BaseGeometryTypeAdapter.java 67.53% <65.00%> (-0.12%) ⬇️
...n/src/main/java/com/mapbox/geojson/MultiPoint.java 66.66% <58.82%> (+14.58%) ⬆️
...eojson/src/main/java/com/mapbox/geojson/Point.java 70.31% <64.00%> (+1.46%) ⬆️
... and 3 more

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jush jush force-pushed the rs/primitives-geojson branch from 3e5fd48 to ef71786 Compare January 30, 2026 06:24
* @see <a href="https://github.com/googlemaps/android-maps-utils/blob/master/library/src/com/google/maps/android/PolyUtil.java">Part of algorithm came from this source.</a>
*/
@NonNull
public static double[] decodeToFlattenListOfPoints(
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a copy paste of above public static List<Point> decode(..) except that it internally uses arrays of doubles that grow (doubles in size) as needed.

@jush jush marked this pull request as ready for review January 30, 2026 12:39
@jush jush requested a review from a team as a code owner January 30, 2026 12:39
@jush jush changed the title Use primitive array in Point instead of List Use flat structure to store lists of points Jan 30, 2026
@jush jush changed the title Use flat structure to store lists of points Use flat double[] structure to store lists of points Jan 30, 2026
@jush jush changed the title Use flat double[] structure to store lists of points Use flat data structure to store lists of points Jan 30, 2026
@jush jush requested a review from dmitry-novikov January 30, 2026 12:43
@jush jush removed the request for review from dmitry-novikov January 30, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants