Repository navigation
Description
Problem
uid_touched and user_touched give Query_Statement an id list per element type, built from every object the users touched (touched_ids_by_users in src/overpass_api/statements/user.cc). Query_Statement::execute intersects it with the ids the other constraints allow. So for a prolific user, the full list is materialised even when another constraint leaves only a handful of possible ids. Example:
[out:csv(::count)]; node(id:1,2,3)(uid_touched:N); out count;
(N stands for a user id.)
With #42, User_Constraint caches the touched lists for the whole query, so the scan runs once. But get_node_ids still hands out a full copy (ids = touched_nodes(rman)), and Id_Constraint::restrict_to (query.cc) copies the caller's list once more while intersecting. For a short moment, three full copies of the node list are alive: the cache, the copy handed out, and the intersection buffer. Upstream peaks at two.
Proposal
Use the hook from #98. Query_Constraint::narrows_by_known_ids() and get_*_ids_within(rman, known, ids) let a constraint whose id list is expensive be asked after the others, with the sorted explicit ids they allow.
User_Constraint::narrows_by_known_ids()returns true for thetouchedcriterion.get_node_ids_within/get_way_ids_within/get_relation_ids_withinreturn the cached list intersected withknown, without copying the full list.- Keep the cache complete:
filterstill needs the full list for exactness. Only the copy handed toQuery_Statementshrinks. - With no explicit list from the other constraints (the "all ids" state), behave as now.
Expected effect
- Memory: the transient copy and the intersection buffer drop from the full list to at most the size of
known. Peak memory for nodes goes from three full lists to one plus small ones, below upstream's two. - CPU: a little less copying and sorting. The metadata scan is unchanged: the cache has to be built in full for
filter. - Results: none can change. Like changed: collect only the ids other constraints allow #98, this only removes ids the caller intersects away.
Dependencies
- Needs the hook from changed: collect only the ids other constraints allow #98 (based on
upstream/master) and the cache from user: compute the ids of touched objects once per query #42 (stacked on user: filter relations by touched ids whenever the set has relations #41). Build it on a branch from user: compute the ids of touched objects once per query #42 with changed: collect only the ids other constraints allow #98's commit cherry-picked, or after one of them is merged, and add it toall-changes, where both already are. - Without user: compute the ids of touched objects once per query #42's cache, the same hook would still let the touched list be filtered against
knownwhile it's built. That lowers memory below upstream, but the metadata is still read twice, which user: compute the ids of touched objects once per query #42 fixes.
Testing
- The targeted user-filter grid from user: compute the ids of touched objects once per query #42: the four user filters × node, way, relation and
nwr× direct, box first, input set andforeach. Add id lists before and after the user filter. bench/fuzz.pywith--features users,history,completeon the history database.- Peak RSS (
--rss) for a user with many touched nodes, with and without an id or tag constraint, against user: compute the ids of touched objects once per query #42. - Mutation test: ignore one known id in the intersection.
Generated by Claude Code
Activity