Repository navigation
perf: faster reading phase (PBF decode, store lookups, relation scan, attribute and index inserts) - #994
Closed
dktue wants to merge 3 commits into
Closed
perf: faster reading phase (PBF decode, store lookups, relation scan, attribute and index inserts)#994dktue wants to merge 3 commits into
dktue wants to merge 3 commits into
Conversation
dktue
force-pushed
the
perf/planet-3min-02-reading-phase
branch
2 times, most recently
from
November 15, 2026 15:21
52df691 to
56e240f
Compare
dktue
force-pushed
the
perf/planet-3min-02-reading-phase
branch
2 times, most recently
from
November 16, 2026 12:27
7d14f0d to
1c14ba2
Compare
This was referenced Nov 16, 2026
dktue
force-pushed
the
perf/planet-3min-02-reading-phase
branch
3 times, most recently
from
November 22, 2026 08:49
52b245b to
8f19529
Compare
…atorArea Most ways run exactly the same Lua as many ways before them: the same tag reads give the same results and the same calls. With `way_memo = true` in the profile, tilemaker records, per thread, a tree of what way_function read (Find, Holds, IsClosed, NextRelation, ...) and which tilemaker functions it then called (Layer, Attribute..., MinZoom), and replays the calls for a way whose reads give the same results, without entering Lua. Ways with anything else (geometry queries, Id, relation tags, globals) run through Lua as before. - Opt-in declarations, documented in CONFIGURATION.md: way_memo_values (tags only tested for being empty and copied, e.g. name; replayed with the way's own value, optionally its length), way_memo_area (MercatorArea only compared with given numbers), way_memo_relations (NextRelation only tested, relation tags only via FindInRelation), and node_memo* for node_function. Multipolygon relations get a record of their own. - The walk reads the way's tags once into small key slots (memo_keys.h); TagMap builds its hash only when Lua asks for a tag. - Bounded: 2^18 nodes per thread, at most 256 children per node, full trees are compacted; a value-heavy branch (a name, a house number) falls back to Lua. - New Lua functions MercatorArea() (planar Web Mercator area) and MinZoomByArea(limit, thresholds): the minimum-zoom-by-area rule worked out in C++, so that way_function stays replayable. - The bundled OpenMapTiles profile uses all of this, and keeps tilemaker's functions in locals. - The Makefile compiles as C++17, like CMake since systemed#953 (memo_keys.h uses std::string_view). Works with Lua 5.1/LuaJIT too (lua_objlen where luaL_len is missing). Output: the only change in this series. The old profile computed MercatorArea in Lua as Area() / cos^2(latitude of the centroid); the native function is the planar area on the Web Mercator plane. Areas close to a minimum-zoom threshold can land on the other side of it, so some landuse, water and building polygons start one zoom earlier or later. Everything else is identical; the memo itself does not change the output. Planet (96 threads): way_function replayed for ~1.17 billion of 1.22 billion ways, node_function for ~211 million nodes; together with the native area about -21% wall. Rebase note (master a2863ae, systemed#928): the residential landuse rule is now systemed#928's, in this profile's style: `if MercatorArea()>ZRES6SQ then SetMinZoomByArea() else MinZoom(8) end`; way_memo_area = { ZRES6SQ }, as ZRES6SQ is now the only number way_function compares MercatorArea() with (it was { ZRES8SQ }). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
SetNameAttributes compares name:<lang> with name when preferred_language or
additional_languages is set; a memo value is only told apart by empty / not
empty, so replayed objects lost or gained name:<lang> / name_int attributes
(Finland with additional_languages { "sv", "de" }: 1,557 tiles differed from
the memo switched off; with this fix: identical). With the default settings
nothing changes.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…erts) Exact speed-ups of reading the .pbf and filling the stores and indexes; output byte-identical. - PBF: packed varints decoded in one SWAR pass; latitude to latp through a polynomial with an exact fallback (checked against the old function for every E7 latitude). - Node/way stores: chunks decoded lazily with a fused SSSE3 decoder, uncompressed chunks kept in the per-thread cache, ways decoded in one pass, a small linestring cache; leftover way groups are moved, not copied, at finalize. Node/way block batches handed out guided. - Relations: UsedWays collects the member ways per thread (a global lock per member way was the main kernel spin-lock cost) and is finalized into a bitmap on all threads (atomic OR; _InterlockedOr64 on MSVC); a thread's list is found by the UsedWays' own number, not its address (a new UsedWays at the address of a destroyed one picked up the old list - seen in the unit test). RelationScanStore finds a way's relations by a hash index, then by sorted shard arrays with a per-reader cursor. Heavy relation blocks go first and the last blocks are split, so the pass doesn't end on one thread. Multipolygon rings are joined in one buffer (no deque, no std::map of done ways), reading each way's coordinates once. - Tags and attributes: TagMap compares keys by an 8-byte prefix; DequeMap gets an open-addressing hash index, hashed once per lookup; the hot attribute-pair shard is read without its lock once it is full. - Output index: small-index adds are staged per thread and appended per shard in bulk (one lock per z6 tile run instead of one per tile); the tiles of a linestring are found faster. - Memory: way pieces are handed to the orphanage in a vector of their own size; the thread's buffer keeps its capacity for the next pieces. Planet (96 threads): about -18% wall over the rounds (e.g. UsedWays -21 s, node decode -18 s, attribute store -9 s). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
dktue
force-pushed
the
perf/planet-3min-02-reading-phase
branch
from
November 23, 2026 02:40
8f19529 to
7747a50
Compare
Contributor
Author
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.
Gain: planet (96 threads) about -18% wall for this PR, compounded over 11 rounds: UsedWays -21 s (paired runs; relation scan 26 s -> 4.5 s, system time 2,754 s -> 497 s), node/PBF decode -18 s, attribute store -9 s, DequeMap index -9 s, PBF decode -4.5 s, UsedWays per thread -4.4 s, smaller ones.
Series total: planet (in memory, 96 threads) about 9:50 for perf/shared-pieces + #989/#990 (Nov 8; glibc, Boost 1.74, GCC 11, Lua 5.3) -> 3:08 for the last commit (Nov 14; jemalloc with THP settings, Boost 1.83, GCC 14, Lua 5.4), -68%. Compounding the per-round A/B measurements, the code of this series accounts for about -63%; the newer toolchain (about -8%) and jemalloc (about -8%) for the rest.
Stacked on the previous PR of this series (
perf/planet-3min-01-lua-memo), so the diff of this PR on GitHub also shows the commits below it; review the last commit. The whole series is onperf/planet-3min.What
Exact speed-ups of reading the .pbf and filling the stores and indexes; output byte-identical.
--storeshard pass. The split of the last relation blocks above is made per pass on a copy of the block list and leaves blocks already subdivided alone, so it neither caused that bug nor needed a change for it.Output
Byte-identical output: the same data in the same stores, found faster; nothing about the order of objects in the tiles changes.
Verification
make test, 18 suites, 0 failures). CI passes on Linux (Makefile with LuaJIT, CMake), macOS (macos-latest) and Windows; macos-14 fails on every PR since GitHub retired that runner (ci: replace the retired macos-14 runner with macos-15 #1002); locally also checked with LuaJIT 2.1 and Boost 1.87 headers.placelayer; the memo records and replays feat(profile): rank place labels by population and declutter them (#517) #1012'sScore()andZOrder()calls like the other calls.make testpasses (18 suites; run at the base, 06 and 08). From commit 01 on the output is again the same at every commit (four extracts, 4 threads, server build: Huron 53564f28, Canberra 9b28be5a, Patagonia cbdf944f, Canary 33574032). It differs from before the rebase only by the output fixes master merged (fix: bbox from pbf header west/south of 0; vector_layers metadata for integer fields and write_to layers #944: metadata and bounds; fix: drop polygon rings that collapse to zero area on the tile grid (#864) #946 and fix: keep small closed ways (roundabouts) that collapse when simplified (#315) #955: some tiles): with those taken out, the final commit gives the files of before the rebase byte for byte (the four extracts at 1, 4 and 16 threads, the Netherlands and Germany with--store). perf: index a sparse multipolygon by clusters of its outers #988 changes only Patagonia: 10 empty z14 tiles are no longer written (the same 10 as on master, c0e221f vs b890cfb); every other tile is byte-identical, and the Netherlands with--storeis unchanged. Fix residential area filtering by size #928 (the bundled profile's minimum zoom for residential landuse) adds residentiallandusefeatures to a few tiles and changes nothing else (Canary 8 tiles, Canberra 3, Patagonia 22, the Netherlands with--store12; Lake Huron unchanged): the same change as on master, b890cfb vs a2863ae. Memo on vs off (Canary Islands, 4 threads; Finland, 6 threads): identical files.SortedNodeStore::contains; this commit leavescontainsas it is, so the check is kept unchanged.addGeometryToIndexfor multipolygons, where this commit restructures the index loop (the rtree per output, the per-tile index in bulk throughaddToSmallIndex). Both are kept: perf: index a sparse multipolygon by clusters of its outers #988's boxes are computed as on master, and every output of a large polygon goes into the rtree under each of them.🤖 Generated with Claude Code