You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Id checks dominate tag-lookup and recursion queries (binary search per candidate) #6
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:
The global tag index returns the matching ids and their quadtiles. For the query above that is 613 nodes in 280 quadtiles.
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.
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.
Activity