Skip to content

Coordinate formatting dominates large geometry outputs #15

Open

Description

@cldellow

Problem

Queries with large outputs spend much of their CPU formatting coordinates. Every latitude and longitude is written as out<<std::fixed<<std::setprecision(7)<<value (72 places in output_formats/output_{json,xml,csv,custom}.cc), which goes through glibc's general-purpose floating-point formatting.

Evidence

On the Nova Scotia test database (see #2), this query takes about 490 ms CPU even with all the changes in #12 (benchmark query q10, 14.5 MB of JSON output):

[out:json]; way[highway](44.60,-63.66,44.70,-63.52); out geom;

Profile (perf, build with all changes applied):

Function Share of CPU samples
__printf_fp_buffer + __mpn_divrem (glibc float formatting) ~14%
stream insertion and fwrite ~6%
collect_tags_framed, make_geometry, LZ4 the rest of the top entries

Proposed fix (no format change, no API change)

Overpass stores coordinates as fixed-point integers (units of 1e-7 degrees), and all output uses exactly 7 decimals. A small formatter can produce the same characters without general float formatting:

  • Fast path: scale by 1e7 and round.
  • Fallback: use snprintf("%.7f") near rounding ties.

The output must stay byte-identical. std::to_chars would be simpler, but it needs C++17, and the build pins -std=c++11.

🤖 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