Skip to content

Id checks dominate tag-lookup and recursion queries (binary search per candidate) #6

Open

Description

@cldellow

Problem

Queries that select objects through an id list spend most of their CPU checking ids. Examples are a tag lookup such as nwr[amenity=restaurant], recursion, and member and parent filters.

Id_Predicate (data/abstract_processing.h) checks every object it is shown with std::binary_search over the sorted id list, and most of those objects are not in the list:

  1. The global tag index returns the matching ids and their quadtiles. For the query above that is 613 nodes in 280 quadtiles.
  2. Every node block of each of those quadtiles is decompressed: 612 blocks, about a third of nodes.bin. In built-up areas a quadtile spans several blocks, and the block index cannot narrow down by id.
  3. Every node in those blocks is binary-searched against the 613 ids: millions of searches to find 613 nodes.

Reproduction

On the Nova Scotia test database (see #2), benchmark query q01:

[out:csv(::count)]; nwr[amenity=restaurant]; out count;

This takes about 160 ms CPU. The profile (perf, fossgis master):

Function Share of CPU samples
LZ4_decompress_safe 43%
std::binary_search (inside Id_Predicate) 36%
block iteration ~10%

Query q02 (node[natural=peak]) behaves the same way, and is slower than q01 despite fewer results. Peaks are spread out, so almost every match is in a different block.

Fix

#1 adds a hashed bit filter in front of the binary search, so most absent ids are rejected with one bit test. q01 drops to 124 ms, or 39 ms with nodes.bin and ways.bin uncompressed.

The decompression cost (step 2) needs either a format change or different compression settings, so it is out of scope for that PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT


Generated by Claude Code

Activity

  1. added
    query-perf
    on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    query-perf

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions