Skip to content

Reduce allocations when building linestrings#7516

Open
leonardehrenfried wants to merge 5 commits intodev-2.xfrom
geometry-optimization
Open

Reduce allocations when building linestrings#7516
leonardehrenfried wants to merge 5 commits intodev-2.xfrom
geometry-optimization

Conversation

@leonardehrenfried
Copy link
Copy Markdown
Member

@leonardehrenfried leonardehrenfried commented Apr 13, 2026

Summary

Reduces allocations by skipping conversions from Linestring to List<Coordinate>.

A few places in the code wastefully construct fully materialized lists of coordinates when the more compact Linestring or CoordinateSequence is available. This code changes that to reduce the number of allocations thereby increasing efficiency.

Unit tests

Two unit tests had to be changed but this code makes the output actually more correct: the previous version included duplicate coordinates, which this PR removes.

Bumping the serialization version id

Transfer is changed, but only the return type of a method, no serialized fields.

@leonardehrenfried leonardehrenfried requested a review from a team as a code owner April 13, 2026 05:52
@leonardehrenfried leonardehrenfried changed the title Geometry optimization Reduce allocations when building linestrings Apr 13, 2026
@leonardehrenfried leonardehrenfried added !Optimization The feature is to improve performance. !Technical Debt Improve code quality, no functional changes. labels Apr 13, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.29%. Comparing base (096bcc7) to head (c94d0ef).
⚠️ Report is 74 commits behind head on dev-2.x.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...analyzer/annotations/TransferCouldNotBeRouted.java 0.00% 1 Missing ⚠️
...entripplanner/transfer/regular/model/Transfer.java 50.00% 1 Missing ⚠️
.../street/model/edge/BoardingLocationToStopLink.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #7516      +/-   ##
=============================================
- Coverage      71.31%   71.29%   -0.03%     
- Complexity     21137    21211      +74     
=============================================
  Files           2357     2365       +8     
  Lines          87556    87753     +197     
  Branches        8665     8681      +16     
=============================================
+ Hits           62438    62560     +122     
- Misses         22108    22179      +71     
- Partials        3010     3014       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

* segment of the pattern visits.
*/
public static List<Coordinate> extractTransitLegCoordinates(
public static LineString extractTransitLegCoordinates(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe we should rename this to extractSubGeometry or something?

vpaturet
vpaturet previously approved these changes Apr 14, 2026
Copy link
Copy Markdown
Contributor

@vpaturet vpaturet left a comment

Choose a reason for hiding this comment

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

This looks good, nothing to mention besides the renaming suggested by Henrik.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

!Optimization The feature is to improve performance. !Technical Debt Improve code quality, no functional changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants