Skip to content

changed: reuse the ids found within the known ids in filter() - #241

Open
cldellow wants to merge 1 commit into
changed-known-idsfrom
changed-reuse-known-ids
Open

cldellow wants to merge 1 commit into
changed-known-idsfrom
changed-reuse-known-ids

Conversation

@cldellow

Copy link
Copy Markdown
Owner

Stacked on #98 (changed-known-ids): it reuses the ids that PR's get_*_ids_within finds. The tables compare against #98's branch.

Fixes #240.

Change

  • Changed_Constraint (statements/changed.cc) keeps, per element type, the ids get_*_ids_within found, with a flag that they are valid.
  • filter() uses them when valid instead of reading the changelog again. Elements outside the known ids fail another constraint anyway, so the result is the same.
  • get_*_ids (the path without known ids) clears the flag, so a statement executed again, as in a loop, can't reuse ids from an earlier execution. In each execution the constraint either computes its ids anew, or is skipped because the result is already empty, in which case filter() has nothing to filter.

One file, 20 lines added, 3 removed. No change to the database format, the query API or the results.

Impact

US northeast full-history extract (Geofabrik), warm cache, 4-core VM. Builds run alternately; median user+sys CPU and peak RSS per query. Base is #98's branch (3331108). 3 alternating runs.

Query CPU, base CPU, this PR change peak, base peak, this PR
f3h1015 10.96 s 6.21 s -43% 12 MB 12 MB
f3h1148 14.46 s 8.16 s -44% 12 MB 12 MB
f3h1238 16.21 s 9.18 s -43% 17 MB 17 MB
f3h138 12.56 s 6.99 s -44% 12 MB 13 MB
f3h399 14.45 s 9.10 s -37% 19 MB 19 MB
f3h515 34.00 s 28.00 s -18% 137 MB 137 MB
f4h1023 15.68 s 8.02 s -49% 11 MB 12 MB
f4h1074 21.53 s 12.24 s -43% 18 MB 18 MB
f4h1119 13.35 s 7.09 s -47% 11 MB 11 MB
f4h162 6.30 s 3.55 s -44% 14 MB 14 MB
f4h600 9.75 s 5.58 s -43% 20 MB 20 MB
total 169.2 s 104.1 s -38.5%

f3h515 gains least: most of its time is a past-date rel(bn)/rel(br) recursion, not the changelog.

Fuzzing, against all-changes: seed 4 with history,users,complete, 1,500 queries: identical output on 1,494, and 6 hit the memory limit on both builds. Total CPU fell 6.9% over the 1,488 completed on both, up to −54% for single queries.

Queries

User names and user ids drawn from the extract are replaced with (user) and N.

f3h1015

[timeout:60][maxsize:536870912][out:json];
nwr(changed:"2013-12-29T19:50:20Z","2023-08-27T16:47:24Z")["barrier"="fence"](43.010830,-73.674143,43.190958,-73.502721)(43.649285,-73.579721,43.654037,-73.287843)->.s0;
complete(5).s0->.s1 { way(around:0)["oneway"]; }
complete(1).s1->.s2 { way(bn)["tiger:reviewed"]; node(w); }
rel(r.s0)->.s3;
.s0 out body;
.s2 out skel asc;
.s3 out count;

f3h1148

[timeout:60][maxsize:536870912];
node[!"crossing:markings"](around:500,42.333170,-71.807030)(changed:"2009-09-11T01:42:39Z")(id:5808248729,7933225701)->.s0;
complete(1).s0->.s1 { way(bn)["addr:street"]; node(w); }
.s1 <<->.s2;
complete(2).s2->.s3 { way(around:0)["addr:housenumber"]; }
.s1 out body bb qt;

f3h1238

[timeout:60][maxsize:536870912];
node["electrified"="no"](around:250,42.437849,-70.979304)["tiger:zip_left_1"~"^17"](changed:"2008-03-26T21:18:32Z")->.s0;
foreach.s0->.it{ .it out ids; (.it; .it >;)->.x; .x out count; }
.s0 out meta bb asc;

f3h138

[timeout:60][maxsize:536870912];
node(changed:"2013-11-29T15:44:12Z")[!"maxspeed"]["tiger:name_type"~"^(Ct|Dr|Pl|Rd|St)$"](id:194643791,1134862311,6869056030,7782629674,7890221078,13265901419)->.s0;
.s0 >->.s1;
node.s0["highway"="motorway_link"]->.s2;
complete(5).s1->.s3 { way(bn)["tiger:county"]; node(w); }
complete(3).s3->.s4 { way(around:0)["footway"]; }
.s0 out count;

f3h399

[timeout:60][maxsize:536870912][out:json];
node(41.586558,-73.808928,41.605927,-73.745478)(changed:"2009-09-29T16:04:57Z","2023-04-05T03:17:31Z")(user_touched:"(user)")["tiger:name_base"~"^La"]->.s0;
rel(br.s0)->.s1;
(.s0; .s0;)->.s2;
.s1 >->.s3;
complete(1).s2->.s4 { node(w); way(bn)["barrier"]; }
.s1 out body geom;
.s2 out ids qt;

f3h515

[timeout:60][maxsize:536870912][diff:"2013-04-10T20:50:31Z","2013-12-04T15:09:54Z"];
nwr["gauge"="1435"](42.200826,-71.451612,42.213341,-71.363218)(changed:"2014-03-29T19:37:46Z","2022-04-05T16:56:26Z")(around:100,40.463690,-79.929815)->.s0;
rel(bn.s0)->.s1;
rel(br.s0)->.s2;
way(r.s0)->.s3;
node(way_cnt.s0:2-)->.s4;
.s0 out ids center;
.s3 out tags;
.s4 out ids 6;

f4h1023

[timeout:60][maxsize:536870912][out:csv(::type,::id,::lat,::lon,"power")];
nwr(changed:"2010-01-05T06:28:39Z")(if:is_tag("tiger:name_base"))[!"network:wikipedia"]["operator"="Town of Cromwell"]->.s0;
retro(date("2014-05-27T19:03:57Z")) { way(if:length()>10)(around:500,41.634834,-70.639757)["operator"="Town of Cromwell"](newer:"2013-04-07T05:40:50Z")->.s1; .s1 out ids; }
node(around.s1:100)["waterway"="river"]->.s2;
complete(3).s1->.s3 { node(w); way(bn)["crossing"]; }
way(r.s1)->.s4;
way.s4(43.593704,-70.690339,43.687566,-70.441537)->.s5;
.s3 out count;
.s4 out ids;

f4h1074

[timeout:60][maxsize:536870912][out:csv(::type,::id,::lat,::lon,"place")];
nw["amenity"="fast_food"](42.708511,-71.582852,42.822834,-71.358014)(changed:"2008-01-09T20:55:37Z","2026-05-12T00:28:20Z")["tiger:name_base"~"^Old\\ Go"]->.s0;
rel(bw.s0)->.s1;
node(way_link.s0:3-)->.s2;
.s0 out meta asc 16;
.s1 out ids (42.794364,-71.251585,42.802414,-71.158149);

f4h1119

[timeout:60][maxsize:536870912];
nw(changed:"2016-10-04T10:47:02Z")["lanes:forward"="1"](42.816813,-78.873734,42.967065,-78.791370)->.s0;
.s0 out body;

f4h162

[timeout:60][maxsize:536870912][out:json];
node(changed:"2017-01-30T05:06:51Z","2022-05-16T20:58:56Z")(id:329476904,2882189650,11023004019)->.s0;
rel(br.s0)->.s1;
way(around.s1:100)["amenity"="parking"]->.s2;
.s0 out ids geom;

f4h600

[timeout:60][maxsize:536870912][out:json];
node(user:"(user)")(changed:"2013-03-27T03:29:37Z","2023-06-23T00:27:32Z")["roof:levels"](id:73598046,178611653,2252333579,5351723285,9048709520,9611828301,10946013125)->.s0;
.s0 convert row ::id=id(),tags=count_tags();
out;
.s0 out meta 45;

Testing

  • Byte-identical output to the base on the 11 queries above.
  • fuzz.py against all-changes, seed 4, history,users,complete: 1,500 queries, no difference.
  • CI: fuzz, history and props run on this PR.

Limitations and open questions



Generated by Claude Code

Changed_Constraint::get_*_ids_within reads the changelog for the given
period and keeps the changed ids among those the other constraints allow.
filter() then read the whole changelog for the period again, to keep the
collected elements that changed. That second read is redundant: an element
outside the known ids fails another constraint anyway, so the ids from the
first read decide the same.

The constraint keeps the ids get_*_ids_within found, per element type, and
filter() uses them instead of reading the changelog again. get_*_ids (the
path without known ids) clears them, so a statement executed again, as in a
loop, can't reuse a previous execution's ids.

On a US northeast full-history extract (Geofabrik), warm cache, 4-core VM,
median of 3 alternating runs:

  node["electrified"="no"](around:250,42.437849,-70.979304)["tiger:zip_left_1"~"^17"](changed:"2008-03-26T21:18:32Z")->.s0; foreach.s0->.it{ .it out ids; (.it; .it >;)->.x; .x out count; } .s0 out meta bb asc;
      CPU 16.21 s -> 9.18 s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01736kJWpJaGbt8ML6jz9N35
@cldellow cldellow added the query-perf Query performance change; collected on all-changes label Nov 26, 2026 — with Claude
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

query-perf Query performance change; collected on all-changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants