Repository navigation
Conversation
This was referenced Nov 29, 2026
cldellow
force-pushed
the
geometry-way-cache
branch
from
November 29, 2026 05:02
a92281f to
1fd6e9f
Compare
Owner
Author
|
First CI run: 6
Cause: with a bounding box, Fix: the relation store uses the cache only when it has no bounding box. Locally (Nova Scotia), all six fuzz queries differ from Generated by Claude Code |
Each Way_Geometry_Store and Relation_Geometry_Store read the nodes (and,
for relations, the member ways) from the database, and every statement and
output that needs geometry builds its own store, so the same ways were read
and built again and again: for an area query with out geom, by the area
filters and again by out geom.
Resource_Manager gets a per-query cache of way geometry, capped at a quarter
of [maxsize:] (32 MiB without one) and outside its accounting like other
auxiliary structures. At the current date, Way_Geometry_Store builds only
the ways it doesn't find there, adding complete geometries while under the
cap, and get_geometry answers from it. Relation_Geometry_Store asks
relation_way_members to skip member ways whose geometry is cached and takes
it from the cache, when it has no bounding box: with one, members outside its
ranges must stay without geometry.
On the Nova Scotia extract of 2026-11-08 with the area rules run, warm
cache, 4-core VM, median CPU of 10 alternating runs:
[out:json][timeout:30]; area(3600390558)->.country; (way["boundary"="administrative"]["admin_level"="8"](area.country); relation["boundary"="administrative"]["admin_level"="8"](area.country); ); out geom;
2.76 s -> 2.04 s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
cldellow
force-pushed
the
geometry-way-cache
branch
from
November 29, 2026 05:17
1fd6e9f to
17cfe2f
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.
Fixes #280.
An alternative to #281, which caches node positions instead; only one of the two should be merged. See the comparison at the end.
Change
Resource_Manager(dispatch/resource_manager.h) gets a per-query cache of way geometry (way_geometry_cache, way id → coordinates) andgeometry_cache_limit(). At the current date:Way_Geometry_Store(data/way_geometry_store.cc) builds only the ways it doesn't find in the cache, adds complete geometries while under the cap (copying the input only when some of its ways are already cached), andget_geometryanswers from the cache first;Relation_Geometry_Store(data/relation_geometry_store.cc) passes the ids of cached member ways torelation_way_membersto skip them, and takes their geometry from the cache, but only when it has no bounding box. With one (out bb (…),out center (…)and so on), members outside its ranges must stay without geometry, so it reads members as before.Queries at a past date keep the old path. 5 files, +92/−8. No change to the database format or the query API.
Impact
CPU time (user + system), Nova Scotia extract of 2026-11-08 imported with
--metaand lz4-compressed maps, with the area rules run, warm cache, 4-core Intel Xeon VM (2.1 GHz), againstupstream/master555f744, 10 alternating pairs; paired ratio with 95% CI. Output identical. The level-8 query isThe level-6 query is the same with
"6"(benchmark p07); "ways only" and "relations only" keep only that statement of the union.upstream/masterPeak memory falls slightly: later stores no longer hold node vectors for ways they find in the cache. The template on the public servers (admin level 4 in a country area,
out geom) runs about 2,800 times a day at about 7.3 s each (#280).Benchmark queries:
timingworkflow (run, commit 17cfe2f, GitHub runner, Nova Scotia): sum of medians 0.945 ofupstream/master. The largest gains are on area and geometry queries; the cost is on single-statement queries that build way geometry but never reuse it, the worst being:[out:csv(::count)]; way[highway](44.60,-63.66,44.70,-63.52); out count;That query's bbox filter builds every crossing way's geometry once, and filling the cache adds a hash insert and a copy per way. In callgrind (Nova Scotia, warm cache) it runs 3.4% more instructions than
upstream/master; the first version, which also copied the input ways when none were cached, ran 6.1% more (CI ratio 1.090).Memory
The cache lives for the whole query, so it is capped at a quarter of
[maxsize:](128 MiB at the default 512 MiB; 32 MiB without a limit), like the union block cache on the all-changes branch. Once full, nothing more is added and stores read from the database as before. It is auxiliary and isn't counted toward[maxsize:]. Each entry is estimated at 64 bytes plus 8 bytes per node of the way; a node shared by several ways is stored once per way.Testing
upstream/master555f744 on the queries above, and on the level-8 query with[maxsize:8000000], where the cache is capped at 2 MB and fills up early.fuzzand 2historydifferences, from relation output with a bounding box; see the comment below. Fixed in the amended commit.fuzz5995 same, 5 skipped;history2000 of 2000 same;props60 seeds, no new failures.Compared with #281
This one is faster and lighter on these queries, and is the version on the all-changes branch; #281 is smaller.
https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
Generated by Claude Code