Repository navigation
Conversation
…:set Meta_Collector loads the metadata of one index (tile) at a time and then only searches it. It kept the entries in a std::set, so every load paid one node allocation and a red-black tree insert per entry, and every lookup walked the tree. Queries that read metadata for many objects (out meta, newer, user filters) spent about a fifth of their time there. Now the entries are appended to a vector, sorted if needed (blocks are usually already in order), and searched with std::lower_bound. Duplicates are removed keeping the first, as std::set::insert did, and reset() still adds to the existing entries without clearing them, so lookups return the same entries as before. Callers use the returned pointer immediately, before the next get(), so a reallocation does not invalidate a pointer still in use. No change to the database format or the query API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
|
Colin's thoughts: low risk, high confidence, medium benefit. Enforce an invariant after a batch of steps, not at every step along the way. Instead of using a set where the invariant is true at all times (but at the cost of tree rebalancing), use a vector, then sort+uniq it once in bulk. |
|
Re-measured independently on a US northeast full-history extract (Geofabrik), base Instruction counts (valgrind callgrind; these repeat exactly between runs of the same build):
CPU time, warm cache, 4-core VM, builds alternating, median of 3 (noise about ±4% per query):
The gain is largest for One detail I noticed while writing it: Small queries for instruction countss_d1_adiff_small s_d2_diff_highways_small s_d4_diff_convert_small s_m1_meta_amenity_small s_m3_attic_meta_small Meta queries m1–m3m1_meta_amenity m2_meta_buildings m3_attic_meta_highways p07 and p13Generated by Claude Code |
Fixes #30.
Change
Meta_Collectorloads one index tile's metadata at a time and then only searches it. It kept those entries in astd::set, so every load paid a node allocation and a red-black tree insert per entry, and every lookup walked the tree.std::vector, sorted only if they arrive out of order (blocks are normally already sorted), and searched withstd::lower_bound.std::set::insertdidreset()still adds to the existing entries without clearing them, as beforeget()returns a pointer into the container. Every caller uses it before callingget()again on the same collector, so a vector reallocation can't invalidate a pointer still in use.One file, about 30 lines. Based on fossgis
master. No change to the database format or the query API.Impact
CPU time (user + system), median of alternating runs against fossgis
master(8edf11b), warm cache, 4-core VM. Output is identical for every query.History database: Nova Scotia, imported directly from a full-history extract with
--keep-attic. 5 runs per build.{{UID}}is the user id with the most current objects in the box. The extract is licensed, so the id isn't given.master[out:csv(::count)]; nwr(newer:"2026-11-08T00:00:00Z")(43.3,-66.5,47.1,-59.6); out count;nwr(uid:{{UID}})(44.60,-63.66,44.70,-63.52); out meta;[out:csv(::count)]; nwr(uid_touched:{{UID}})(44.60,-63.66,44.70,-63.52); out count;[diff:"2026-11-12T00:00:00Z","2026-11-19T00:00:00Z"]; nwr(44.60,-63.66,44.70,-63.52); out meta;[date:"2018-01-01T00:00:00Z"][out:csv(::count)]; nwr[amenity](44.60,-63.66,44.70,-63.52); out count;[date:"2018-01-01T00:00:00Z"][out:csv(::count)]; way[highway=primary](44.60,-63.66,44.70,-63.52); (._;>;); out count;For the
uid_touchedquery, the two builds' ranges overlap (1,830–2,031 ms against 1,831–1,974 ms).Plain database: Geofabrik Nova Scotia extract of 2026-11-08, imported with
--meta. 7 runs per build.master[out:xml]; nwr[amenity](44.60,-63.66,44.70,-63.52); out meta;(q08)[out:xml]; nwr(44.640,-63.590,44.655,-63.570); (._;>;); out meta;(q12, shaped like a JOSM download)The other benchmark queries (q01–q07, q09–q11; see #2) read no metadata. Cached-baseline runs put them within noise of
master; the sum over q01–q12 is −4%.Testing
bench/fuzz.pyon thebench-toolsbranch), againstmaster:--features users, 0 differences (5 timeouts skipped). In a run with the same settings, 885 of 2,000 queries used metadata:out meta: 499version(),timestamp(),changeset(),uid(),user()evaluators: 42–56 eachMemory
The vector replaces a set of the same entries. It's bounded by one tile's metadata, as before, and is smaller per entry (no tree node). Peak RSS doesn't change measurably:
masternewerquery aboveuidquery aboveLimitations and open questions
Generated by Claude Code