Repository navigation
Description
uid_touched queries decompress every metadata block they need twice.
Query
[out:csv(::count)]; nwr(uid_touched:N)(44.60,-63.66,44.70,-63.52); out count;
N is a user id. Measured with the id of the user with the most current objects in the box. That id comes from a licensed extract, so it isn't given.
Measurement
fossgis master (8edf11b), with throwaway instrumentation that counts decompressions per (file, block) (not on any branch). The database is a Nova Scotia history database imported from a full-history extract with --keep-attic.
| File | Decompressions | Distinct blocks | Ratio |
|---|---|---|---|
nodes_meta.bin |
7,708 | 3,854 | 2.00 |
nodes_meta_attic.bin |
2,726 | 1,363 | 2.00 |
ways_meta_attic.bin |
458 | 229 | 2.00 |
ways_meta.bin |
442 | 221 | 2.00 |
relations_meta_attic.bin |
40 | 20 | 2.00 |
relations_meta.bin |
14 | 7 | 2.00 |
nodes.bin |
348 | 93 | 3.74 |
ways.bin |
187 | 95 | 1.97 |
| All files | 11,935 | 5,891 | 2.03 |
Every metadata file is read exactly twice. That suggests two full passes over the same metadata: probably one to find where the user's edits are, and one to filter the candidates. The second pass starts only after the first has read everything, so a cache would have to hold every block the query touches, which a bounded per-query cache can't.
Cost
The query takes about 1.9 s of CPU on the baseline, 22% of it in LZ4_decompress_safe, which is about 35 µs per block. The second metadata pass costs about 5,900 extra decompressions, about 210 ms or 11% of the query, plus parsing those blocks again. user_touched probably behaves the same way, but hasn't been measured.
Possible fix
Not investigated yet. The first step is finding the two passes in statements/user.cc and the query statement, then checking whether the first pass's result (the indexes or ids it found) can be kept and reused by the second, with no change to the format or the query API.
Generated by Claude Code
Activity
cldellow commentedon Nov 21, 2026
Cause found and fixed in #42. With
uid_touched, the query engine callsUser_Constraint::get_node_ids(and the way and relation versions) to restrict candidates, and laterUser_Constraint::filter. Both calltouched_ids_by_users, which scans all of the user's current and attic metadata over the same ranges. That's the exact 2.00× on every metadata file. Inside a loop, both scans repeat every iteration.#42 keeps the touched ids for the rest of the query, up to 2M ids per object type. For users under that bound:
foreachover 76 cafés runningnwr(around.it:100)(uid_touched:N)is 22–24× fasterThe most prolific local user exceeds the bound for nodes, so for them only the way and relation scans are saved (−8%). The bound is an open question in that PR.
A bug found along the way: #39. In the same function, the relation step was guarded by the node condition, so relations were not filtered when the set had no nodes. Fixed in #41, which #42 is stacked on.
Generated by Claude Code