Repository navigation
Conversation
The geometry helpers in around.cc (cartesian, sum, cross_prod, rescale) and the Prepared_Segment/Prepared_Point members used std::vector<double> for 3-element vectors, so every intersection test allocated and freed several small heap buffers. On larger inputs around makes hundreds of millions of these tests. Use std::array<double, 3>. The arithmetic is unchanged, so results are identical. way(around.s0:100) with 282 ways in .s0 (Nova Scotia extract): 24.1 s -> 10.1 s CPU. around queries against small sets are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
This was referenced Nov 20, 2026
Owner
Author
|
Colin's thoughts: Low risk, high confidence, high benefit. Move heap allocations to the stack by eliminating a vector that is constant size. |
cldellow
pushed a commit
that referenced
this pull request
Nov 23, 2026
…ions (#7) When this function was first created, it applied the filter unconditionally: https://github.com/fossgis/Overpass-API/blame/46abfbeda4d774db76f502156aa0416b9742f517/src/overpass_api/statements/user.cc#L203-L208 A subsequent commit introduced a guard. The guards for nodes/ways are correct, the guard for relations is not: https://github.com/fossgis/Overpass-API/blame/8edf11b0419c39df4cd074bb83b6854392e57b13/src/overpass_api/statements/user.cc#L252-L256 The result is that the filter is not correctly applied in all cases. For example, querying for a relation touched by a non-existent user will always find the relation: ``` rel(1); nwr._(uid_touched:999999999); out ids; ``` If you broaden the input to include a node so that the relation filter code path is exercised, the output is correct: ``` (rel(1); node(1);); nwr._(uid_touched:999999999); out ids; ``` With the fix, the two queries return the same result - the empty set.
cldellow
added a commit
that referenced
this pull request
Nov 27, 2026
Add run_testsuite_regressions.sh, which runs every test in
osm-3s_testing/input/regression_*/ and compares its output with
expected/regression_*/, and call it from run_testsuite.sh. Each test is
one directory, so a fix can add its test without changing a script:
stdin.log the query (for a CGI test, the request body, if any)
init.osm optional: data imported into a database of the test's own
import.args optional: arguments for update_database (default --meta)
env optional: run cgi-bin/interpreter with these environment
variables instead of osm3s_query, with a dispatcher over
the test's database
Each test runs for at most 60 seconds and writes at most 10 MB per file,
so a test of a hang fails rather than blocks the suite. The database is
created with mktemp, because the dispatcher's socket path in a directory
under osm-3s_testing/run can exceed the length limit for socket paths.
osm-3s_testing/README.regressions describes how to add a test.
The tests:
- regression_ql_nesting_limit (04c045b, "Stop the OverpassQL parser
looping past the nesting limit"): node(1); inside 1024 levels of
parentheses. The parser reports that nesting is limited to 1023 levels
and stops. Without the fix, it reports parse errors without end.
- regression_user_touched_relations (#7): on one relation, way and two
nodes by uid 1,
rel(1); nwr._(uid_touched:999999999); out count;
rel(1); nwr._(uid_touched:1); out count;
count 0 and 1 relations. Without the fix, the first counts 1 relation.
- regression_cgi_custom_url_line_break (#4): a GET request for
data=[out:custom];node(1);out; with url=http://example.com/%0d%0aX-Injected:%201
is rejected with 400 Bad Request. Without the fix, the response is a
302 redirect with an extra header line "X-Injected: 1".
- regression_cgi_bbox_not_numeric (#4): a GET request for
data=node(bbox);out; with bbox=7,51,8);node(id:1,52 fails to parse.
Without the fix, the value is substituted as is, the query becomes
node(51,7,52,8);node(id:1);out; and returns node 1.
Reverting one fix on this branch makes its tests fail and no others:
git revert -n 04c045b # regression_ql_nesting_limit
git revert -n 4a9c1b5 # regression_user_touched_relations
git revert -n -m 1 8edf11b # the two regression_cgi_* tests
Not covered: the parts of #4 that leave the output of these requests
unchanged (reading the POST body in chunks, a "%" at the end of the
input, the scope of the "=" search, the operates_* checks in
pt_diagrams), the cgi-bin shell scripts of #3, and #8 and #11, which
change only performance.
Co-Authored-By: Colin Dellow <cldellow@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4.
Change
statements/around.ccstored every 3-element vector in a heap-allocatedstd::vector<double>. That covers the helperscartesian,sum,cross_prodandrescale, and thePrepared_Segment/Prepared_Pointmembers. Everyintersect()call therefore allocated and freed three small buffers, and largearoundqueries make hundreds of millions of these calls.This switches them to
std::array<double, 3>(Vec3). The arithmetic is unchanged, so results are identical.Two files changed, all within
around. No change to the database format or the query API.Impact
Wall time per query (single-threaded, so close to CPU time), Nova Scotia test database (see #2), compared with
master:masteraroundagainst small sets (benchmark q06:node[amenity=cafe](bbox); node(around:300)[shop], and other spot checks)Full text of the timed queries
A (282 ways around a point in Dartmouth, then everything within 100 m of them):
B (nodes and ways within 1 km, then ways within 100 m of them):
The profile share of
malloc/free/operator newwas about 30% on the first query; the rest of the gain likely comes from cheaper arithmetic without the indirection.The quadratic cost itself remains; #3 covers that, with a follow-up PR stacked on this one.
Memory
This reduces memory. Each
Prepared_Segmentshrinks from 4 doubles plus 3 heap-allocated vectors (about 220 bytes including allocator overhead) to 13 doubles (104 bytes), andPrepared_Pointshrinks similarly. Nothing new is allocated.Testing
aroundspot-check queries.master. 2,997 identical, 3 skipped (timeouts on both builds), 0 differences.complete). That covered 10,000 queries across the plain, area and history databases (6,000 / 2,000 / 2,000), with 0 differences. The per-PR fuzz run above predates a fuzzer fix: about 8% of its queries were invalid on both builds, so it rests on roughly 5,500 queries that ran (see Benchmark queries and differential fuzzer #2).Limitations
aroundwith way or relation sets, so the effect on server load is unknown.Generated by Claude Code