Skip to content

Reuse one line intersector for all obstacle candidates of a profile - #1008

Open
sachabaclet wants to merge 1 commit into
Universite-Gustave-Eiffel:mainfrom
sachabaclet:perf_profile_intersections
Open

Reuse one line intersector for all obstacle candidates of a profile#1008
sachabaclet wants to merge 1 commit into
Universite-Gustave-Eiffel:mainfrom
sachabaclet:perf_profile_intersections

Conversation

@sachabaclet

Copy link
Copy Markdown
Contributor

The problem

For every candidate wall or ground border of a cut profile, addGroundBuildingCutPts called LineSegment.intersection, which creates a new RobustLineIntersector and its internal arrays on each call. A JFR recording of an urban run with order-2 reflections showed this single call site producing 29% of the allocation pressure of the whole computation.

The change (+6/−2 lines)

  • One RobustLineIntersector is created per profile and reused for every candidate. The intersection test is exactly what LineSegment.intersection does internally, so the computed coordinates are identical. The returned coordinate was already copied right after the test, which makes the reuse safe.
  • The list of new cut points becomes an ArrayList instead of a LinkedList.

For every candidate wall or ground border of a cut profile,
addGroundBuildingCutPts called LineSegment.intersection, which creates
a new RobustLineIntersector and its internal arrays on each call. A JFR
recording of an urban run with reflections showed this single call site
producing 29% of the allocation pressure of the whole computation.

The intersector is now created once per profile and reused for every
candidate. The returned coordinate was already copied right after the
test, so the reuse is safe. The list of new cut points also becomes an
ArrayList instead of a LinkedList. The computed intersections are
exactly the ones LineSegment.intersection returns, so the results are
unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sachabaclet
sachabaclet requested a review from a team July 12, 2026 13:27
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