Reduce non-intersecting map archive downloads - #136
Open
FrogAi wants to merge 2 commits into
Open
Conversation
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
Content-Lengthfrom 65.41 GB to 43.54 GB (33.44%).Root cause
Map downloads currently round each region's rectangular bounding box outward to the 2-degree archive grid, then request every archive in that rectangle. Large or irregular regions such as Alaska and Canada therefore request many archive groups that do not intersect the selected region.
The archives already contain road data rather than terrain or ocean layers. The unnecessary cost comes from selecting irrelevant archive groups, so this change narrows the requested coordinates without changing the contents of any individual archive.
Change
archive_rangesfield to download-menu entries. Each row is[latitude, inclusive minimum longitude, exclusive maximum longitude]for one 2-degree latitude band.scripts/update_download_regions.pyto check or regenerate the ranges from pinned Natural Earth country boundaries and Census TIGER/Line state boundaries.Download impact
7201c6b4eb23a2abContent-LengthContent-LengthContent-LengthContent-LengthThe region-summed rows reflect independently downloading each menu region, which matches the current downloader's behavior. The unique-union rows count each archive coordinate once and describe total catalog coverage.
Compatibility and scope
bounding_boxcontinue to use the previous behavior. Omitted or emptyarchive_rangesalso fall back to the bounding box.Engineering record and validation
Design decisions
Boundary-generation policy
The updater pins:
f1890d9f152c896d250a77557a5751a93d494776, SHA-256239eec57ac17f100a11e2536cffc56752c318b50ae765b0918ff7aab4ce8f255.59a220888a8d9be8117c4fcd38f542bd02d81abf0d198c78113595ad540dd957.uvmetadata.Each existing menu bounding box is rounded to the archive grid and used as the policy seed for selecting source polygon components. Selected components are retained whole so ordinary boundary corrections are not clipped by stale decimal bounds. Their intersecting 2-degree archives are then compacted into latitude rows.
Natural Earth's nonstandard country identifiers are handled explicitly:
FR,NO, andTWare selected throughADM0_A3valuesFRA,NOR, andTWN. mapd's historicalus_state.GMentry maps to CensusSTUSPS=GU.Invalid source geometry is repaired with Shapely
make_validbefore component selection. Antimeridian jumps are rejected instead of generating ambiguous longitude ranges.The updater never adds or removes region definitions in the download catalog. New countries and newly relevant detached territories require an intentional menu change and review of the generated diff.
The candidate union removes 3,159 legacy coordinates and adds 12 coordinates reached by retaining selected components whole, producing a net reduction of 3,147 coordinates.
Measurement method
The live sweep ran from 2026-08-22 16:03:13 through 16:15:53 UTC. Base coordinates were derived from each menu bounding box using mapd's 2-degree floor/ceiling behavior. Candidate coordinates used non-empty
archive_rangeswhen present and the same bounding-box fallback otherwise.Each coordinate maps to
https://map-data.pfeifer.dev/offline/{latitude}/{longitude}.tar.gz. The combined base/candidate union contained 9,862 unique archive coordinates, each mapping to one URL. The audit queried every URL exactly once withHEADusing 24 workers, a 30-second timeout, and up to four attempts with exponential backoff. A parseable positiveContent-Lengthwas required. Every URL passed on its first attempt, so no retries were used and no archive payloads were downloaded.One coordinate-to-size map was then summed two ways:
Unrounded
Content-Lengthtotals:65,410,800,451 -> 43,535,791,51123,952,699,874 -> 23,907,153,7651,436,458,288 -> 504,505,1022,415,287,103 -> 11,561,464The displayed MB and GB values use decimal units. The totals exclude HTTP/TLS overhead, retries, and extracted on-disk size.
The one-off measurement harness and per-URL manifest were not retained. Boundary and menu generation remain reproducible from pinned sources, but the historical size figures are contemporaneous evidence and cannot be independently recalculated or diagnosed per coordinate from the retained record. Because hosted archive sizes can change, rerunning this method verifies the current hosted data rather than the exact historical totals above.
Validation
Compared:
7201c6b4b4ec1b0b9ea21daa8c05b80fdd7e01eeeb23a2ab25557cb4aa62384878cf589a2b4512bfThe candidate changes only:
docs/overriding-internal-defaults.mdscripts/update_download_regions.pysettings/download.gosettings/download_menu.jsonExact-head checks:
uv run scripts/update_download_regions.py --check229 regions, 184 with explicit ranges; 17238 legacy archive occurrences -> 8613 selectedgo test ./...go vet ./...docker buildx build --platform linux/arm64 --load .uvx ruff format --check --config "indent-width=2" --config "line-length=160" scripts/update_download_regions.pygit diff --check 7201c6b4b4ec1b0b9ea21daa8c05b80fdd7e01ee...eb23a2ab25557cb4aa62384878cf589a2b4512bfAudit-only external geometry reconstruction across all 229 entries:
The exact-head Go tests and vet ran in a Linux/amd64 container. The Docker build compiled the candidate for Linux/ARM64.
No exact-head race test or on-device/end-to-end map download was performed. No permanent tests for the new selection behavior are included.
The one-off independent geometry checker was not retained. Its results are contemporaneous audit evidence rather than durable regression coverage; the committed updater's
--checkmode remains the reproducible check that pinned sources generate the committed menu.