Skip to content

tags: remove redundant sorts of the candidate ids for late tag checks - #15

Open
cldellow wants to merge 1 commit into
fossgis:masterfrom
cldellow:tags-late-sort-once
Open

cldellow wants to merge 1 commit into
fossgis:masterfrom
cldellow:tags-late-sort-once

Conversation

@cldellow

Copy link
Copy Markdown

This PR speeds some queries by removing unnecessary sorts.

First: both overloads of generate_ids_by_coarse sorted each coarse index's ids a second time, after already sorting them and removing duplicates.

I belive this was a merge artifact from several years ago. The final sort in generate_ids_by_coarse was added in 9ea00f9 (2016-06-06) on the out_csv_finetuning branch. master had meanwhile also added sort + unique (3935810, c30c154), and the branch merges (2fd080e, 8ccb933) kept both loops, so since 2017-03-03 the lists have been sorted twice.

Impact on queries:

Geofabrik Nova Scotia extract:

  [out:json]; (node["shop"](44.45,-63.80,44.85,-63.40); node["amenity"](44.45,-63.80,44.85,-63.40); node["tourism"](44.45,-63.80,44.85,-63.40); ); out count;
      638 ms -> 561 ms (-13%)

A similar speed-up is observed in the much denser Boston area on the northeast-us extract:

  [out:json]; (node["shop"](42.16,-71.26,42.56,-70.86); node["amenity"](42.16,-71.26,42.56,-70.86); node["tourism"](42.16,-71.26,42.56,-70.86); ); out count;
      2.54 s -> 2.30 s (-9%)

Second: filter_ids_by_tags sorts the ids before checking each required key. The first key's ids are always already sorted, so it now sorts only if std::is_sorted says they aren't.

Impact on queries:

  [out:json][timeout:25]; (node["amenity"~"fuel|cafe"]["brand"~"tim hortons|irving|esso|shell|petro-canada|ultramar|circle k|needs|starbucks",i](44.45,-63.85,44.85,-63.35); node["amenity"~"fuel|cafe"]["name"~"tim hortons|irving|esso|shell|petro-canada|ultramar|circle k|needs|starbucks",i](44.45,-63.85,44.85,-63.35); way["amenity"~"fuel|cafe"]["brand"~"tim hortons|irving|esso|shell|petro-canada|ultramar|circle k|needs|starbucks",i](44.45,-63.85,44.85,-63.35); node["shop"~"supermarket|convenience"]["brand"~"sobeys|superstore|atlantic superstore|walmart|lawtons|shoppers drug mart|foodland",i](44.45,-63.85,44.85,-63.35); way["shop"~"supermarket|convenience"]["brand"~"sobeys|superstore|atlantic superstore|walmart|lawtons|shoppers drug mart|foodland",i](44.45,-63.85,44.85,-63.35); ); out center tags;
    896 ms -> 852 ms (-5%)

Remove two redundant sorts, and add a guard to avoid a redundant sort in
some cases:

- generate_ids_by_coarse (both overloads) sorted each coarse index's ids
  a second time, after already sorting them and removing duplicates.
- filter_ids_by_tags sorts the ids before checking each required key.
  The first key's ids are always already sorted, so it now sorts only if
  std::is_sorted says they aren't.

Geofabrik Nova Scotia extract, warm cache, 25 alternating pairs:

  [out:json]; (node["shop"](44.45,-63.80,44.85,-63.40); node["amenity"](44.45,-63.80,44.85,-63.40); node["tourism"](44.45,-63.80,44.85,-63.40); ); out count;
      638 ms -> 561 ms (-13%)

Co-Authored-By: Colin Dellow <cldellow@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants