Repository navigation
Conversation
…istance LongArrayDistanceMatrix.bulkWriter(origins, destinations) looks up each location once and returns a writer that puts a distance by the position of its locations in the two lists. put() looks up both locations and adds both ids to the origin and destination sets for each distance, which dominates the time to fill a large matrix. The rule that maps a location pair to its array slot is now in one method, which get(), put() and the writer use.
Without the check, the capacity arithmetic overflows for 46,340 locations, so the writer skips the resize and fails at a later put.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The bulk writer mutates matrix state before rejecting oversized input, leaving it unusable for later writes, and indexed LinkedList access makes registration quadratic.
2 open issues
What changed in this PR
Adds a position-based bulk writer to speed up distance-matrix loading without repeated location lookups for each distance.
Changes:
- Adds bulk location registration and indexed distance writes.
- Shares array-slot calculation across reads and writes.
- Adds six tests covering bulk writes, resizing, existing locations, and input validation.
| File | Description |
|---|---|
| service/maps/api/src/test/java/ai/timefold/solver/service/maps/impl/LongArrayDistanceMatrixTest.java | Tests bulk-writer behavior and validation. |
| service/maps/api/src/main/java/ai/timefold/solver/service/maps/impl/LongArrayDistanceMatrix.java | Implements the bulk writer and shared slot calculation. |
Review effort: Balanced
The size check now counts the new locations of both lists before registration starts. Before, a rejected call left the extra locations in the matrix, so every later bulkWriter call failed. Registration iterates the lists instead of get(i), so it stays linear for lists without random access, such as a LinkedList.
larsbeck
requested review from
jennedebleser
and
a balanced review from Copilot
December 4, 2026 13:47
This branch has not been deployed
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
LongArrayDistanceMatrix.bulkWriter(origins, destinations)returns a writer that puts a distance by the position of its two locations in the given lists. It looks up each location once per call, not once per distance.Why
put(from, to, distance)looks up both locations in aHashMapand adds both ids to the origin and destination sets for each distance. For a full matrix of 10,000 locations, that is 100 million calls, and these look-ups take most of the time to fill the matrix. A caller that fills a full matrix, or a block of one, can use the writer instead.Measured on a laptop: filling a travel-time matrix and a distance matrix for 10,000 locations from a routing response took 8.7 s with
put()and 1.2 s with the writer (median of 5 runs).Changes
bulkWriter(List<Location>, List<Location>)and the nestedBulkWriterclass. The locations count as origins and destinations from the call on, and the matrix grows if it needs more space.IllegalArgumentExceptionif the matrix would have more than the maximum number of locations.get(),put()and the writer use one method that maps a location pair to its array slot.Compatibility
New public method and class in the
implpackage.revapipasses.Tests
./mvnw -pl service/maps/api clean install: 51 tests pass (6 new for the writer).🤖 Generated with Claude Code
https://claude.ai/code/session_01UUczJSzTQ9zXe1wLE2raD9