Skip to content

Area queries decode boundary vertices again for every tested coordinate #27

Open

Description

@cldellow

Problem

Area queries such as "every highway in Halifax" spend much of their CPU decoding the area's boundary coordinates over and over.

Coord_Query_Statement::check_area_block (statements/coord_query.cc) tests whether a coordinate lies inside an area. It ray-casts against an "area block", a chain of boundary segments stored per tile. Each call decodes every vertex of the block from Overpass's packed format with ::ilat/::ilon, bit-deinterleaving that costs about a dozen operations per coordinate.

Area_Query_Statement (statements/area_query.cc) tests many coordinates against the same blocks of a tile:

  • every candidate node
  • every way vertex
  • the midpoint of every way segment, in has_inner_points

So the same vertices are decoded once per tested coordinate. It also walks every block in full, even when the coordinate's longitude lies outside the block's longitude range, where no segment can affect the result.

Evidence

Nova Scotia test database with the standard area rules run (see #2):

[out:csv(::count)]; area[name="Halifax"][admin_level=8]->.a; way[highway](area.a); out count;

This returns 16,841 ways and takes about 1,000 ms CPU. Profile (perf, build with the changes in #12):

Function Share of CPU samples
check_area_block, inclusive 41%
inlined ilon/ilat decoding about 33%
has_inner_points 16%
loading way geometry (Way_Geometry_Store) 15%

For [out:csv(::count)]; area[name="Halifax Regional Municipality"]->.a; way[building](area.a); out count; (161,374 buildings, about 2 s), check_area_block is 22%.

Proposed fix (no format change, no API change)

  • Decode once per tile: decode each area block once per tile, and test coordinates against the decoded vertices.
  • Reject by longitude: skip a block outright when the coordinate is outside its longitude range. Every case in check_area_block other than "ignore this segment" needs the coordinate's longitude within the segment's span, so the result for such a block is 0.

🤖 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