Repository navigation
Description
The tools used to find performance problems in this fork and to check changes for correctness. They live under bench/ on the bench-tools branch, and bench/README.md has the usage. Performance results for the combined changes are in #12, and each PR carries its own.
Tools
Every tool that compares builds takes a baseline (--a) and a candidate (--b), so it can be reused on any change.
| Tool | Question it answers | Output |
|---|---|---|
compare.py |
Is the change faster? Does it change the output of the benchmark queries? | Median CPU time (user + system) per query and build, output equality, and optionally peak RSS (--rss). Baseline timings are cached; --no-cache alternates runs of both builds instead, for differences under about 25%. |
fuzz.py |
Does the change alter any result? Which queries are pathologically slow or memory-hungry? | Every query whose output or errors differ, saved for reproduction. With --report, one CSV row per query with CPU time (and peak RSS with --rss) per build. |
fuzz_vocab.py |
The vocabulary fuzz.py draws tags, ids, roles, coordinates, users and edit times from, built from an extract with osmium. |
|
test_fuzz.py |
Does the generator still produce every construct it should? | Coverage of each construct at a minimum share of queries, reproducibility, and (given a build) that the queries parse. |
deadline_audit.py |
Which loops ignore the query's [timeout:]? |
Fuzz queries run with a short [timeout:] that overrun it by a margin, with the statement where the limit was finally noticed. |
pick_vars.py |
Values for {{NAME}} placeholders in benchmark queries, chosen from a database, for values that can't be committed. |
Test databases
All are built from Geofabrik extracts of Nova Scotia.
| Database | Built from | Used for |
|---|---|---|
| Plain | the extract of 2026-11-08 (12.6M nodes, 882k ways, 20.6k relations), imported with --meta |
q01–q12; fuzzing without optional features |
| Areas | a copy of the plain database with the standard area rules run (osm3s_query --rules < rules/areas.osm3s) |
a1–a4, t01–t11; fuzz.py --features areas,complete |
| Full-history | a full-history extract (every version from 2006-03-21 to 2026-11-15: 20.3M node, 2.1M way and 131k relation versions), imported with osmium cat extract.osh.pbf -f osh | update_database --keep-attic, using update_database from the better-imports branch |
h1–h6; fuzz.py --features history,users,complete |
About the full-history database:
- It's licensed and private. Nothing derived from it is committed or published: not the database, the fuzz vocabulary, query outputs, or user names, ids or changeset ids. Results from it are given in aggregate, and queries that need a user id use the
{{UID}}placeholder. - Use the
better-importsbuild.master'supdate_databasecomputes old way versions' geometry from today's nodes (Direct full-history import builds wrong geometry for old way versions #34). - Don't pass
--metawith--keep-attic. Both set the same mode, and the later flag wins, so--metaafter--keep-atticsilently drops the history. - Checked against osmium: current node, way and relation ids match exactly. Node counts and way ids in the Halifax box at 2014, 2018 and 2022 match
osmium time-filter(ways also throughextract -s complete_ways). At 2010, 6 of 1,793 ways are missing, because they reference nodes that don't exist at that date anywhere in the extract.
Benchmark queries
Four sets, in bench/queries/, bench/queries-areas/, bench/queries-history/ and bench/queries-tools/. Each runs with compare.py on its own database. The baseline is master (8edf11b): median CPU time (user + system), warm page cache, 4-core VM. Run-to-run noise is about ±10% per query, more on the history set.
Plain database (7 runs):
| Query | What it exercises | Text | Result | master |
|---|---|---|---|---|
| q01 | Global tag lookup, all types | [out:csv(::count)]; nwr[amenity=restaurant]; out count; |
791 | 160 ms |
| q02 | Global lookup of a rare tag | [out:csv(::count)]; node[natural=peak]; out count; |
567 | 183 ms |
| q03 | Bbox scan of all nodes | [out:csv(::count)]; node(44.60,-63.66,44.70,-63.52); out count; |
510,340 | 47 ms |
| q04 | Bbox plus tag | [out:csv(::count)]; way[highway](44.60,-63.66,44.70,-63.52); out count; |
20,845 | 139 ms |
| q05 | Recurse down from ways | [out:csv(::count)]; way[highway=motorway]; (._;>;); out count; |
19,973 | 140 ms |
| q06 | around a node set |
[out:csv(::count)]; node[amenity=cafe](44.60,-63.66,44.70,-63.52); node(around:300)[shop]; out count; |
686 | 104 ms |
| q07 | Large relation, full recursion | [out:csv(::count)]; rel[boundary=administrative][admin_level=4][name="Nova Scotia"]; (._;>>;); out count; |
290,117 | 682 ms |
| q08 | out meta |
[out:xml]; nwr[amenity](44.60,-63.66,44.70,-63.52); out meta; |
2.9 MB XML | 388 ms |
| q09 | out geom, small box |
[out:json]; way[building](44.640,-63.585,44.655,-63.565); out geom; |
950 KB JSON | 59 ms |
| q10 | out geom, large box |
[out:json]; way[highway](44.60,-63.66,44.70,-63.52); out geom; |
14.5 MB JSON | 470 ms |
| q11 | Recurse up | [out:csv(::count)]; node[highway=traffic_signals](44.60,-63.66,44.70,-63.52); way(bn); rel(bw); out count; |
350 | 60 ms |
| q12 | JOSM-style download | [out:xml]; nwr(44.640,-63.590,44.655,-63.570); (._;>;); out meta; |
16.4 MB XML | 768 ms |
Area database (5 runs):
| Query | What it exercises | Text | Result | master |
|---|---|---|---|---|
| a1 | Nodes in a small area, selective tag | [out:csv(::count)]; area[name="Halifax"][admin_level=8]->.a; node[amenity=cafe](area.a); out count; |
119 | 65 ms |
| a2 | Ways in an area | [out:csv(::count)]; area[name="Halifax"][admin_level=8]->.a; way[highway](area.a); out count; |
16,841 | 1,072 ms |
| a3 | Many ways in a large area | [out:csv(::count)]; area[name="Halifax Regional Municipality"]->.a; way[building](area.a); out count; |
161,374 | 1,960 ms |
| a4 | is_in for a set of nodes |
[out:csv(::count)]; node[amenity=cafe](44.60,-63.66,44.70,-63.52); is_in; out count; |
195 | 170 ms |
Full-history database (5 alternating runs):
| Query | What it exercises | Text | Result | master |
|---|---|---|---|---|
| h1 | Box + tag at a past date | [date:"2018-01-01T00:00:00Z"][out:csv(::count)]; nwr[amenity](44.60,-63.66,44.70,-63.52); out count; |
1,804 | 1,390 ms |
| h2 | Changes in a box between two dates | [diff:"2026-11-12T00:00:00Z","2026-11-19T00:00:00Z"]; nwr(44.60,-63.66,44.70,-63.52); out meta; |
2.1 MB XML | 7,329 ms |
| h3 | Objects edited since a date, province-sized box | [out:csv(::count)]; nwr(newer:"2026-11-08T00:00:00Z")(43.3,-66.5,47.1,-59.6); out count; |
23,910 | 5,926 ms |
| h4 | Recursion at a past date | [date:"2018-01-01T00:00:00Z"][out:csv(::count)]; way[highway=primary](44.60,-63.66,44.70,-63.52); (._;>;); out count; |
1,246 | 460 ms |
| h5 | One user's current objects in a box, with metadata | nwr(uid:{{UID}})(44.60,-63.66,44.70,-63.52); out meta; |
not given | 1,836 ms |
| h6 | Objects a user ever touched in a box | [out:csv(::count)]; nwr(uid_touched:{{UID}})(44.60,-63.66,44.70,-63.52); out count; |
not given | 2,193 ms |
{{UID}} is the user id with the most current objects in the box, written to a file by pick_vars.py and passed with compare.py --vars. It comes from licensed data, so neither it nor h5's and h6's results are given.
Tool-shaped queries (area database, 5 alternating runs). Real traffic comes largely from a few client tools, each sending fixed query shapes, so these are built from the templates in those tools' source code and filled in for Halifax. overpass turbo, JOSM, QGIS QuickOSM, osmnx, osmdata and MapComplete use Overpass; iD, StreetComplete, Every Door, OsmAnd and Organic Maps use the OSM editing API instead.
| Query | Tool | Text | master |
|---|---|---|---|
| t01 | overpass turbo, default example | node[amenity=drinking_water](viewport); out; |
38 ms |
| t02 | overpass turbo wizard, "in Halifax" | [out:json][timeout:25]; area(id:3609092218)->.searchArea; nwr["amenity"="restaurant"](area.searchArea); out geom; |
151 ms |
| t03 | overpass turbo wizard, bbox | [out:json][timeout:25]; nwr["shop"](city bbox); out geom; |
289 ms |
| t04 | overpass turbo, cycle network example | [out:json]; (relation[route=bicycle](city bbox); way[highway=cycleway](city bbox); way[highway=path][bicycle=designated](city bbox);); out body; >; out skel qt; |
268 ms |
| t05 | JOSM, full download | [out:xml]; (node(viewport); <;); (._;>;); out meta; |
626 ms |
| t06 | JOSM query wizard | [out:xml][timeout:90][bbox:city bbox]; (nwr["shop"];); (._;>;); out meta; |
338 ms |
| t07 | QuickOSM, "in Halifax" | [out:xml] [timeout:25]; area(3609092218) -> .area_0; (node["amenity"="restaurant"](area.area_0); way["amenity"="restaurant"](area.area_0); relation["amenity"="restaurant"](area.area_0);); (._;>;); out body; |
171 ms |
| t08 | osmnx graph_from_place, network_type="drive" |
[out:json][timeout:180];(way["highway"]["area"!~"yes"]["access"!~"private"]["highway"!~"<highway list>"]["motor_vehicle"!~"no"]["motorcar"!~"no"]["service"!~"<service list>"](poly:'<Halifax boundary>');>;);out; |
1,496 ms |
| t09 | osmnx features_from_place, amenity=restaurant |
[out:json][timeout:180];((node['amenity'='restaurant'](poly:'<Halifax boundary>');(._;>;););(way['amenity'='restaurant'](poly:'<Halifax boundary>');(._;>;););(relation['amenity'='restaurant'](poly:'<Halifax boundary>');(._;>;););out; |
211 ms |
| t10 | osmdata | [out:xml][timeout:25]; (node ["amenity"="restaurant"] (city bbox); way ["amenity"="restaurant"] (city bbox); relation ["amenity"="restaurant"] (city bbox);); (._;>;); out body; |
179 ms |
| t11 | MapComplete | [out:json][timeout:30][bbox:44.6400,-63.5875,44.6560,-63.5575];(nwr["amenity"="bench"];nwr["leisure"="playground"];nwr["amenity"="waste_basket"];);out body;out meta;>;out skel qt; |
150 ms |
- viewport is the box
44.6440,-63.5800,44.6520,-63.5650, and city bbox is44.5812,-63.7227,44.7112,-63.5427, the bounding box of Halifax (relation 9092218, area id 3609092218). <Halifax boundary>is the outer ring of relation 9092218 from the public extract: 1,041 points aslat lonpairs. osmnx also buffers the ring by 500 m; these queries don't.<highway list>isabandoned|bridleway|bus_guideway|construction|corridor|cycleway|elevator|escalator|footway|no|path|pedestrian|planned|platform|proposed|raceway|razed|rest_area|service|services|steps|track, and<service list>isalley|driveway|emergency_access|parking|parking_aisle|private, both osmnx's.
Differential fuzzer
fuzz.py generates random Overpass QL queries and runs each one on both builds, reporting any query whose output or errors differ.
What it generates. Queries follow the Overpass QL grammar in overpass-ebnf (checked against v0.7.62.11), with values from the vocabulary, so most of them return data. They favour the paths that select objects by id:
- Selection: id filters, bboxes, the global
[bbox:],aroundpoints and sets, andpoly:filters (star-shaped, 3 to 400 vertices, double or single quotes). - Navigation: recursion (
>,>>,<,<<), member and parent filters with roles and way positions,way_cntandway_link. - Logic: unions, differences,
foreach,if:evaluators (includingversion(),timestamp(),changeset(),uid()), andconvert. - Tag filters: exact, exists, negated, regex, case-insensitive, key regex, and alternations over several values as osmnx (
["highway"!~"abandoned|bridleway|track"]) and osmdata (["k"~"^(v1|v2)$"]) write them. - Output: JSON, XML and CSV;
ids,skel,body,tagsandmeta, withgeom,bb,center, sorting and limits. - Optional families (
--features): areas (areaby name and by id in both thearea(id:N)andarea(N)forms,is_in,map_to_area,pivot); history ([date:],[diff:],[adiff:],newer,changed,retro,timeline); user filters anduser(); andcompleteloops.
What it guarantees.
- Reproducible: query N of seed S depends only on S, N and the vocabulary (each run prints its hash), so any query can be reprinted with
--show. - Errors count: errors on stderr are part of each outcome, and the summary lists the most common ones. Before this was added, about 8% of generated queries were invalid on both builds and counted as identical. PR fuzz results from before then rest on about 92% of the queries they cite.
- Limits are skipped, not compared: a run that hits the timeout or the memory limit counts as skipped.
How it's checked.
-
test_fuzz.pyfails, naming the construct, if one of the constructs above stops being generated, for example whenpoly:or area-by-id generation is removed on purpose. -
Mutation testing: to check that the fuzzer would notice a real bug, we plant one on purpose and see whether it's caught. For example, a build whose id lookup silently skips about 1% of ids (every id divisible by 97) gave different output on 262 of 3,000 queries. Some of those queries never filter by id, such as this one:
[timeout:60][maxsize:536870912]; way(around:500,43.982032,-66.146913)->.s0; .s0 out body qt 19;It still lost ways, because Overpass looks up each way's nodes by id internally. So the fuzzer catches bugs in shared code even through queries that don't obviously use it.
Changes that prune or skip work also get a targeted check of the paths they touch, which random fuzzing reaches too rarely, and a mutation test. Those are described in each PR.
Degenerate-query hunts
Each hunt runs fuzz queries on one build and looks for timeouts, memory-limit failures and slow queries (fuzz.py --report), or for overrun time limits (deadline_audit.py).
| Date | Build | Database and features | Queries | Found | Outcome |
|---|---|---|---|---|---|
| 2026-11-21 | master |
plain; areas with areas,complete |
4,000 | 6 timeouts, 4 memory-limit failures, 13 slow queries, all in around |
All finish on all-changes in 0.1–8.8 s, against 3.6–119 s or a limit on master: fixed by the around changes |
| 2026-11-21 | master |
full-history (direct import, before #34 was fixed) with users,history,complete |
2,500 | 9 timeouts, 2 memory-limit failures, 36 slow queries; 38 of the 47 combine around with a past date |
Caused by the broken import (#34), since fixed; not yet re-run on the re-imported database. The other around outliers take under 1 s on all-changes |
| 2026-11-21 | all-changes (#12) | plain, areas, full-history | 9,000 | No timeouts or memory-limit failures. 2 queries over 5 s, one a legitimately heavy around over province-long route relations |
Nothing new to fix |
| 2026-11-21 | master |
plain; full-history with history,users,complete; [timeout:2] |
4,000 | 4 queries overrunning their limit by 7–29 s, all in around |
#8 (second commit) |
Gaps
- Not real traffic. The benchmark queries are hand-written or built from client-tool templates; production CPU may be dominated by other shapes. A sample of real queries would be a better benchmark.
- Tied to Nova Scotia. The boxes, names and boundary assume that extract, which is also small and sparse next to a dense city.
- Warm cache only. Cold-cache runs would show the disk side.
- Fuzzer coverage is set by the generator's weights, not measured. Code coverage data would show which paths it misses.
- Every fuzz query sets
[maxsize:], while client tools don't by default. - No automatic shrinking. A failing query has to be minimised by hand.
🤖 Generated with Claude Code
https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
Generated by Claude Code
Activity
[-]Sample benchmark queries (Nova Scotia extract)[/-][+]Benchmark queries & fuzzing[/+][-]Benchmark queries & fuzzing[/-][+]Benchmark queries and differential fuzzer[/+]