perf(partition): sequential shrinking diffs + reused scratch — national build 39s → 5s#32
Merged
Merged
Conversation
…ed scratch A national NOAA partition build (1707 cells, 6 tiers) took ~39-48 s, all in ownedAtTierIndexed. perf put ~40% of wall-clock in the boolean sweep and ~25% in the kernel (mmap/munmap + faulting fresh pages). Two causes, two changes: - owned = cov \ (∪ overlapping finer cells) built its subtrahend with unionAll — a pairwise fold whose accumulator grows toward whole-district size, O(N²) sweep work when hundreds of finer cells overlap one coarse cell. But A \ (B ∪ C ∪ …) = ((A \ B) \ C) \ …, so diff sequentially: the subject only SHRINKS from one cell's coverage, every subtrahend is a single cell's coverage, and a subject emptied early (a fully covered gap-filler, the common case) exits without touching the rest. - The boolean intermediates freed each op straight back to the page allocator (chosen to keep a pooling gpa from parking whole-district scratch); that was the syscall storm. They now live in a scratch arena reset with retained capacity per cell — no munmap churn, and RSS is still bounded by the largest single cell's working set, not the district. Same NOAA build: 38.7 s -> 5.1 s (sys 11.4 s -> 0.3 s); the composed tile output is byte-identical and the ownedAtTier cross-check suite passes.
OpenCompose round-trips tile57_chart_open across cgo once per archive, each standing up (and tearing down) its own std.Io.Threaded pool — ~35 ms per chart, a minute of boot for a ~1700-cell library. tile57_compose_tree walks, mmaps and composes the whole tree inside one engine call on its batch path; wrap it. Measured in chartplotter: provider registration 60 s -> 7 s.
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.
A national NOAA partition build (1707 cells, 6 tiers) spent ~39–48 s almost
entirely in
ownedAtTierIndexed.perfput ~40% of wall-clock in the booleansweep and ~25% in the kernel (mmap/munmap + faulting fresh pages). Two causes,
two fixes in
src/geometry/plane.zig:1. Drop the per-cell union — diff sequentially.
owned = cov \ (∪ overlapping finer cells)built its subtrahend withunionAll,a pairwise fold whose accumulator grows toward whole-district size — O(N²) sweep
work when hundreds of finer cells overlap one coarse cell. But
A \ (B ∪ C ∪ …) = ((A \ B) \ C) \ …, so we diff sequentially: the subject onlyshrinks from one cell's coverage, every subtrahend is a single cell's coverage,
and a subject emptied early (a fully-covered gap-filler, the common case) exits
without touching the rest.
2. Reuse scratch instead of freeing to the OS.
The boolean intermediates were freed each op straight back to the page allocator
(to keep a pooling gpa from parking whole-district scratch) — that was the
syscall storm. They now live in a scratch arena reset with retained capacity per
cell: no munmap churn, and RSS stays bounded by the largest single cell's working
set, not the district.
Result
Same NOAA build: 38.7 s → 5.1 s (sys 11.4 s → 0.3 s). Composed tile output
is byte-identical; the
ownedAtTiercross-check suite passes.Also on this branch
bindings/go: OpenComposeTree(81b925e) — a one-call open of a whole baked treevia
tile57_compose_tree, replacing per-archivetile57_chart_openround-tripsthat each stood up their own
std.Io.Threadedpool (~35 ms/chart). Chartplotterprovider registration: 60 s → 7 s.