Skip to content

diff: move tags and geometry into the *_With_Context records - #218

Open
cldellow wants to merge 1 commit into
masterfrom
diff-context-move
Open

cldellow wants to merge 1 commit into
masterfrom
diff-context-move

Conversation

@cldellow

Copy link
Copy Markdown
Owner

Fixes #217.

Change

  • Node_With_Context, Way_With_Context and Relation_With_Context (data/diff_set.h) take tags and geometry by value and std::move them into their members. The callers' x ? *x : T() temporaries now move in, so each element's tags and geometry are copied once instead of twice.

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

Impact

Verdict: no measurable gain. The copies are real, but against the rest of a diff (reading two versions of every element, attic reconstruction, output) they are a fraction of a percent.

US northeast full-history extract (Geofabrik), warm cache, 4-core VM, base build upstream/master a9d8f15.

Instruction counts (valgrind callgrind, user-space instructions for the whole run). These repeat exactly between runs of the same build for these queries, so differences well under 1% are real. (p15 of the production set is left out: its count varies by 20% between identical runs.)

Query master this PR change
s_d1_adiff_small 12.462 G 12.445 G -0.14%
s_d2_diff_highways_small 7.901 G 7.881 G -0.25%
s_d4_diff_convert_small 17.678 G 17.679 G +0.00%

CPU time. Base and patched builds run alternately, 3 times each; median user+sys CPU per query. Run-to-run noise is about ±4% per query and ±2% on a total, so small changes don't show here.

Query master this PR change
d1 16.82 s 16.70 s -1%
d2 6.46 s 6.27 s -3%
d3 9.23 s 9.11 s -1%
d4 6.90 s 6.92 s +0%
total 39.4 s 39.0 s -1.0%

Peak memory is unchanged (within 1 MB on every query). Identical output on all queries.

Small queries for instruction counts

s_d1_adiff_small

[adiff:"2025-01-01T00:00:00Z","2026-11-01T00:00:00Z"]; (node["amenity"](42.34,-71.10,42.37,-71.04); way["building"](42.35,-71.07,42.36,-71.05); ); out geom;

s_d2_diff_highways_small

[diff:"2024-01-01T00:00:00Z","2026-11-01T00:00:00Z"]; way["highway"](42.34,-71.08,42.36,-71.05); out geom;

s_d4_diff_convert_small

[diff:"2024-01-01T00:00:00Z","2026-11-01T00:00:00Z"]; nwr["amenity"](42.34,-71.08,42.36,-71.05); convert item ::id=id(), name=t["name"], amenity=t["amenity"]; out;

s_m1_meta_amenity_small

node["amenity"](42.3,-71.15,42.4,-71.0); out meta;

s_m3_attic_meta_small

[date:"2022-01-01T00:00:00Z"]; way["highway"](42.34,-71.08,42.36,-71.05); out meta;
Diff queries d1–d4

d1_adiff_amenity_buildings

[adiff:"2025-01-01T00:00:00Z","2026-11-01T00:00:00Z"]; (node["amenity"](42.2,-71.3,42.5,-70.9); way["building"](42.3,-71.15,42.4,-71.0); ); out geom;

d2_diff_highways

[diff:"2024-01-01T00:00:00Z","2026-11-01T00:00:00Z"]; way["highway"](42.3,-71.2,42.4,-71.0); out geom;

d3_adiff_routes

[adiff:"2025-06-01T00:00:00Z","2026-11-01T00:00:00Z"]; relation["route"="bus"](42.2,-71.3,42.5,-70.9); out geom;

d4_diff_convert

[diff:"2024-01-01T00:00:00Z","2026-11-01T00:00:00Z"]; nwr["amenity"](42.3,-71.2,42.4,-71.0); convert item ::id=id(), name=t["name"], amenity=t["amenity"]; out;

Testing

  • Byte-identical output to upstream/master on the 7 diff queries above.
  • CI: fuzz, history and props run on this PR.

Limitations and open questions

  • Worth merging only as tidying: it is safe and simple, but buys about 0.1–0.25% on diff/adiff. Closing it is also reasonable.


Generated by Claude Code

Set_Comparison builds a Node_, Way_ or Relation_With_Context for every
element of a diff. Their constructors took tags (and, for ways and
relations, geometry) by value or const reference and copied them into the
member. The callers pass "tags ? *tags : std::vector<...>()", a temporary
copy, so each element's tags and geometry were copied twice.

The constructors now take tags and geometry by value and move them into
the members, so the temporary moves in and each is copied once.

On a US northeast full-history extract (Geofabrik), instruction counts
(valgrind callgrind) against master:

  [diff:"2024-01-01T00:00:00Z","2026-11-01T00:00:00Z"]; way["highway"](42.34,-71.08,42.36,-71.05); out geom;
      7.901 G -> 7.881 G (-0.25%)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01736kJWpJaGbt8ML6jz9N35
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.

diff: each element's tags and geometry are copied twice into the comparison records

2 participants