Reduce non-intersecting map archive downloads - #136
Open
FrogAi wants to merge 2 commits into
Open
Conversation
FrogAi
force-pushed
the
codex/optimize-map-downloads
branch
2 times, most recently
from
August 23, 2026 00:01
2c7e34c to
a35dbc1
Compare
FrogAi
force-pushed
the
codex/optimize-map-downloads
branch
from
August 23, 2026 00:29
a35dbc1 to
f538b5e
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
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.go run ./cmd/update-download-regionsto check the committed ranges andgo run ./cmd/update-download-regions --writeto regenerate them from pinned Natural Earth and Census sources.Download impact
7201c6b4f538b5e1Content-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.go-shpparser is only linked into the updater;orbwas already in mapd's dependency closure throughosm.Engineering record and validation
Design decisions
cmdtarget so regeneration-only source parsing is not linked into the mapd binary.Boundary-generation policy
The updater pins:
f1890d9f152c896d250a77557a5751a93d494776, SHA-256239eec57ac17f100a11e2536cffc56752c318b50ae765b0918ff7aab4ce8f255.59a220888a8d9be8117c4fcd38f542bd02d81abf0d198c78113595ad540dd957.Country GeoJSON is decoded with
orb; Census ZIP/SHP/DBF data is decoded withgo-shpand converted toorbpolygons. Downloaded source bytes are accepted only when they match the pinned SHA-256.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.The Go updater evaluates source rings directly and does not add a general geometry-repair dependency. The pinned Natural Earth Egypt self-intersection was explicitly checked against the expected archive set during the port. Unsupported antimeridian jumps are rejected instead of producing 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 size sweep was originally recorded against
eb23a2ab25557cb4aa62384878cf589a2b4512bf. The Go port at the current head reproduces the same ranges and effective archive coordinates byte-for-byte, so the measurements still apply to the current selection behavior.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:
7201c6b4b4ec1b0b9ea21daa8c05b80fdd7e01eef538b5e13dd0755939b8839c9c4e7640ebd4e90bThe candidate changes only:
cmd/update-download-regions/geometry.gocmd/update-download-regions/main.gocmd/update-download-regions/menu.gocmd/update-download-regions/sources.godocs/overriding-internal-defaults.mdgo.modgo.sumsettings/download.gosettings/download_menu.jsonExact-head checks:
go run ./cmd/update-download-regionsdownload menu is up to date (229 regions, 184 with explicit ranges; 17238 legacy archive occurrences -> 8613 selected)go test ./...go vet ./...docker buildx build --platform linux/arm64 --load .git diff --check 7201c6b4b4ec1b0b9ea21daa8c05b80fdd7e01ee...f538b5e13dd0755939b8839c9c4e7640ebd4e90bAudit-only reconstruction and differential checks:
go-shpis linked only into the standalone updater and not into the production mapd binary.The exact-head Go tests and vet ran in a Linux/amd64 container. The Docker build compiled the candidate for Linux/ARM64 and produced a static binary.
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 and formatting checkers were not retained. Their results are contemporaneous audit evidence rather than durable regression coverage; the committed updater's check mode remains the reproducible check that pinned sources generate the committed menu.