Skip to content

parent relations: test a candidate's members without decoding it - #278

Open
cldellow wants to merge 1 commit into
masterfrom
relation-members-in-place
Open

cldellow wants to merge 1 commit into
masterfrom
relation-members-in-place

Conversation

@cldellow

Copy link
Copy Markdown
Owner

Fixes #276.

Change

Get_Parent_Rels_Predicate and Get_Parent_Rels_Role_Predicate (data/abstract_processing.h) tested each candidate relation through h.object(), which decodes it into a Relation_Skeleton with its member and index vectors. They run on every candidate of rel(bn) and rel(bw), and on every relation in the database for rel(br), which scans them all (#277). Most candidates don't match.

has_a_child_with_id and has_a_child_with_id_and_role get overloads on the stored form. Members are 12 bytes each from byte 16: a 64-bit ref, then a 32-bit word with the role in its low 24 bits and the type in its high byte, as Relation_Skeleton(void*) reads them. The predicates' Handle< Relation_Skeleton > overloads use them, so only matching relations are decoded. Attic relations keep the decoding path.

One file, +30/−2. No change to the database format or the query API.

Impact

CPU time (user + system), warm cache, 4-core Intel Xeon VM (2.1 GHz), against upstream/master 555f744, alternating pairs; paired ratio with 95% CI. Output identical. France is the Geofabrik extract, Nova Scotia the 2026-11-08 extract, both imported with --meta and lz4-compressed maps. The VM had been restarted shortly before these runs, so absolute times are higher than in earlier PRs; the paired ratios are unaffected.

Query Database Pairs upstream/master This PR Ratio (95% CI)
[out:csv(::count)]; rel(48.8500,2.3300,48.8840,2.3650); rel(br); out count; France 25 592 ms 532 ms 0.876 (0.843–0.910), faster in 24 of 25
JOSM-style download, central Paris (below) France 25 2,429 ms 2,393 ms 0.971 (0.937–1.007), 16 of 25
the same, central Halifax (below) Nova Scotia 15 371 ms 359 ms 0.977 (0.906–1.054), 8 of 15
Paris:   [bbox:48.8500,2.3300,48.8840,2.3650]; (node(48.8500,2.3300,48.8840,2.3650); way(bn); node(w); ); (._; (rel(bn)->.a; rel(bw)->.a; ); rel(br); ); out meta;
Halifax: [bbox:44.6400,-63.5900,44.6740,-63.5550]; (node(44.6400,-63.5900,44.6740,-63.5550); way(bn); node(w); ); (._; (rel(bn)->.a; rel(bw)->.a; ); rel(br); ); out meta;

The JOSM-style template runs on the public servers about 1,760 times a day at about 5.7 s each. On France, rel(br) is a small part of it: most of the 2.4 s is output (104 MB). On a planet database, rel(br) scans about ten times as many relations, so it should take a larger share there. Not measured.

On the all-changes branch (#12), where output is already cheaper, the template is 0.932 (0.907–0.959) faster with this change.

Benchmark queries: sums of medians over 3 pairs, 0.99 on the plain set (21 queries) and 1.02 on the area set (16); none uses rel(bn), rel(bw) or rel(br). The timing workflow measures them properly.

Testing

  • Output identical to upstream/master 555f744 on the queries above and on the 37 benchmark queries (Nova Scotia, 3 alternating pairs each).
  • CI: fuzz, history, props and timing run on this PR.

Limitations


Generated by Claude Code

Get_Parent_Rels_Predicate and Get_Parent_Rels_Role_Predicate tested each
candidate relation through h.object(), which decodes it into a
Relation_Skeleton with its member and index vectors. They run on every
candidate of rel(bn) and rel(bw), and on every relation in the database for
rel(br), which scans them all; most candidates don't match.

has_a_child_with_id and has_a_child_with_id_and_role get overloads on the
stored form: members are 12 bytes each from byte 16, a 64-bit ref and then a
32-bit word with the role in its low 24 bits and the type in its high byte.
The predicates' Handle overloads for current relations use them, so only
matching relations are decoded.

On the Geofabrik France extract (--meta, lz4-compressed), warm cache, 4-core
VM, median CPU of 25 alternating runs:
  [out:csv(::count)]; rel(48.8500,2.3300,48.8840,2.3650); rel(br); out count;
    592 ms -> 532 ms

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
@cldellow cldellow added the query-perf Query performance change; collected on all-changes label Nov 29, 2026 — with Claude

Copy link
Copy Markdown
Owner Author

CI against upstream/master 555f744: fuzz (run) 6,000 queries, 5,995 same, 5 skipped (timeouts), 0 differences; history (run) 2,000 queries, all same; props (run) 60 seeds, no new failures; timing (run) total 1.000, no query faster or slower (none of the 27 benchmark queries uses rel(bn), rel(bw) or rel(br)), outputs identical.


Generated by Claude Code

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.

Parent-relation predicates decode every candidate relation to test its members

2 participants