Skip to content

uid_touched/user_touched: narrow the touched ids to the ids other constraints allow #100

Open

Description

@cldellow

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 the touched criterion.
  • get_node_ids_within / get_way_ids_within / get_relation_ids_within return the cached list intersected with known, without copying the full list.
  • Keep the cache complete: filter still needs the full list for exactness. Only the copy handed to Query_Statement shrinks.
  • 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

Testing


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions