Build CGPaths during parallel projection, not on every draw call - #43
Merged
Merged
Conversation
4 tasks
The two GeoMapView subclasses (AppKit + UIKit) used to reconstruct `CGMutablePath` from raw `Point` arrays on every `setNeedsDisplay`, including trivial redraws — `mapBackground` toggles, tile arrivals triggering a re-render, drag-frame invalidations, mapOutline flips. The path-building loop is now done once inside a new `projectInParallelCG` alongside the projection math, producing pre-built `CGPath` objects stored in CG-specific projected types (`CGProjectedLine`, `CGProjectedPolygon`, `CGProjectedContent`). The `draw([CGProjectedContent])` path then just calls `context.addPath(path)` — no allocation, no per-vertex iteration per frame. Polygon interior holes switch from a `CGContext` clip-state approach to even-odd fill on a compound path, which also fixes a latent clip-leak when polygons with interiors were followed by polygons without. Parallel projection chunk size is 5 (vs. the original 25 in `projectInParallel`) so finer-grained work distributes more evenly across cores. `projectInParallel` / `draw([ProjectedContent])` stay untouched for SVG output. Ported from claude/investigate-map-performance-rb4u7 (commit 5c59a00) onto today's layout — handles the tiledBaseMap case added since, and the UIKit CTM counter-flip for raster underlays. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
nighthawk
force-pushed
the
perf/prebuilt-cgpaths
branch
from
September 20, 2026 22:34
df79f57 to
cdcb05d
Compare
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.
Summary
GeoMapViewused to rebuildCGMutablePathfrom rawPointarrays on everysetNeedsDisplayeven for redraws that don't touch the geometry (e.g.,mapBackground/mapOutlinetoggles, re-render on tile arrival, invalidation on drag). Now the path-building loop runs once alongside the projection math on the background task, anddraw(_:)iscontext.addPath(path).Also folds the polygon-interior "clip out holes" step into an even-odd fill on a compound path, which has the same visual result but no
CGContextclip state that could leak into the next polygon.Test plan
swift test— 53 tests pass.CGMutablePath.addLinegone fromdraw(_:)samples.