Repository navigation
Conversation
|
Colin thoughts: haven't reviewed this yet. If memory is the concern, check with upstream to see what would be reasonable. Also considering using something like roaring bitmaps or streamvbyte, depending on how exactly the data is used. |
|
Colin's thoughts: low risk, high confidence, medium benefit. This is a only-do-things-once optimization, reuse work to avoid decompressing multiple times. The question is whether we should have a cap above which we fall back to the old behaviour. IMO, we should just be uncapped, I believe the previous code already required loading all the IDs into memory at once. gall/lambert aren't constrained on RAM. Also removing the cap for the biggest user in Nova Scotia was "at a cost of 9.4 MB more peak memory", which, lol. I think we can spare that. (Yes, yes, Nova Scotia is a podunk province. Still.) Needs followup: remove the cap, measure impact, re-assess PR changes. |
|
Follow-up done: the cap is removed (second commit). The user with the most edits in the extract now gets the full speedup: −39% on the box query and 124.7 s → 6.1 s on the 76-iteration loop, with identical output. Peak RSS for the box query goes from 75.9 to 85.1 MB. Upstream already holds two copies of the node list during Generated by Claude Code |
|
Colin's revised thoughts after followup: low risk, high confidence, likely high benefit for the specific case of user queries. I think the code may even read more clearly now. |
For uid_touched and user_touched, User_Constraint scanned all of the users' current and attic metadata (touched_ids_by_users) in get_node_ids, get_way_ids and get_relation_ids, and again in filter. When the query engine used both, as it does when these filters choose the candidates, every metadata block was decompressed twice. Inside a loop, both scans repeated in every iteration. The touched ids depend only on the users, so they are the same for the whole query. The constraint now keeps them after first use, and both callers share them. A list longer than 2M ids (16 MB) is not kept: it is handed over or dropped after use, as before, so a prolific user's ids never stay in memory longer than they did. calc_ranges_both, which computed the same ranges as calc_ranges_32 and calc_ranges_31 together, is no longer needed. On the Nova Scotia history database, with N a user id: [out:csv(::count)]; nwr(uid_touched:N)(44.60,-63.66,44.70,-63.52); out count; drops from 2.02 s to 1.20 s, and a foreach over 76 cafes running nwr(around.it:100)(uid_touched:N) from 126 s to 6 s, with identical output. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
The previous commit kept the touched ids only for lists of up to 2M ids, so the most prolific users, likely the ones queried most, still had their metadata read twice. Upstream already holds a full id list from get_node_ids while filter builds a second one, so keeping one list costs no more than that for nodes. The way and relation lists are smaller, and the bound is removed. On the Nova Scotia history database, for the user with the most edits in the extract (N their user id): [out:csv(::count)]; nwr(uid_touched:N)(44.60,-63.66,44.70,-63.52); out count; drops from 1.99 s to 1.22 s (it was 2.20 s with the bound). Peak RSS goes from 75.9 to 85.1 MB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
a02a1f5 to
a95d1a5
Compare
0430ee9 to
4a9c1b5
Compare
Fixes #32.
Base: this PR was stacked on #41 (the relations fix for the touched filters). Upstream has since merged #41, and this fork's
masternow includes it, so this PR targetsmasterand its diff shows only the cache. The "Base" column below is that relations fix.Change
For
uid_touchedanduser_touched,User_Constraintscanned all of the users' current and attic metadata (touched_ids_by_users) inget_node_ids,get_way_idsandget_relation_ids, and again infilter. When the query engine uses both, as it does when these filters choose the candidates, every metadata block was decompressed twice. Inside a loop, both scans repeated in every iteration.The touched ids depend only on the users, so they are the same for the whole query:
calc_ranges_both, which computed the same ranges ascalc_ranges_32andcalc_ranges_31together, is removed.One file. No change to the database format or the query API.
Update: an earlier version didn't keep lists longer than 2M ids, which excluded the most prolific users. That bound is gone (second commit), for the reasons under Memory.
Impact
CPU time (user + system) on the Nova Scotia history database (#2), warm cache, 4-core VM, against the base branch (the relations fix). Median of 5 alternating runs for the first query, one run per build for the loop. Output is identical for every row. The users are identified by their rank in edit count in the extract, since their ids come from licensed data.
[out:csv(::count)]; nwr(uid_touched:N)(44.60,-63.66,44.70,-63.52); out count;[out:csv(::count)]; node[amenity=cafe](44.64,-63.60,44.66,-63.56)->.c; foreach.c->.it { nwr(around.it:100)(uid_touched:N); out count; }(76 iterations)Nis the user's id.Testing
users,history,complete, 0 differences (3 timeouts skipped). The earlier version also passed 2,500 such queries, 1,000 on the plain database, and 300 against itself.uid,user,uid_touched,user_touched) to nodes, ways, relations andnwr. Each is written one of four ways: directly, with the box first, on an input set, or inside aforeach. 53 returned data. 0 differences from the base branch.Memory
Each list costs 8 bytes per touched node and 4 bytes per touched way or relation, and lives until the query ends. Like other auxiliary structures, it isn't counted toward
[maxsize:].Upstream already holds a full node list while it builds a second one: the list from
get_node_idslives inQuery_Statement::executethroughapply_all_filters, which callsfilter. Here the second list is the kept one, so the extra peak over upstream is the way and relation lists. In a loop, upstream frees its lists between iterations, while this PR keeps them, but it no longer recomputes them.Peak RSS, first query above: user #1 75.9 → 85.1 MB; user #10 24.0 → 21.0 MB; user #20 10.7 → 11.8 MB. Loop: user #1 67.5 → 69.8 MB.
Limitations and open questions
https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT