Repository navigation
Description
Running osm3s_query with jemalloc or mimalloc instead of glibc's malloc cuts CPU time by 3–5% on the plain benchmark queries and by 11–13% on heavy history and metadata queries. Output and peak memory are about the same, and no source changes are needed.
Why look
In perf profiles of history and metadata queries on fossgis master, malloc, _int_malloc, _int_free and cfree together take about 10–13% of samples. Overpass allocates many small vectors and tree nodes per block it processes.
Method
The baseline binary (fossgis master, 8edf11b) was run unchanged, through a wrapper that sets LD_PRELOAD to the allocator and execs osm3s_query, so it is a single process. Allocators: jemalloc 5.3.0 and mimalloc 2.1.2, the Ubuntu 24.04 packages (libjemalloc2, libmimalloc2.0).
Measurements are median CPU time (user + system) of alternating runs against the same binary without the preload, warm cache, 4-core VM. Output is identical for every query.
Plain database
Geofabrik Nova Scotia extract of 2026-11-08, imported with --meta. 5 runs per build.
| Query | glibc | jemalloc | mimalloc |
|---|---|---|---|
| Sum of the 12 benchmark queries | 3,266 / 3,326 ms | 3,172 ms (−3%) | 3,167 ms (−5%) |
[out:xml]; nwr[amenity](44.60,-63.66,44.70,-63.52); out meta; |
382 / 378 ms | −1% | −9% |
[out:json]; way[highway](44.60,-63.66,44.70,-63.52); out geom; |
495 / 556 ms | −1% | −10% |
[out:csv(::count)]; rel[boundary=administrative][admin_level=4][name="Nova Scotia"]; (._;>>;); out count; |
717 / 723 ms | −5% | −3% |
[out:xml]; nwr(44.640,-63.590,44.655,-63.570); (._;>;); out meta; |
742 / 759 ms | −5% | −3% |
The glibc column gives the baseline from each paired run (jemalloc run / mimalloc run). Most single-query differences here are within this VM's noise of about ±5%. The benchmark queries are listed in #2.
History database
Nova Scotia, imported from a full-history extract with --keep-attic. 3 runs per build. {{UID}} is the user id with the most current objects in the box; it comes from licensed data, so it isn't given.
| Query | glibc | jemalloc | mimalloc |
|---|---|---|---|
[diff:"2026-11-12T00:00:00Z","2026-11-19T00:00:00Z"]; nwr(44.60,-63.66,44.70,-63.52); out meta; |
6,878 / 6,686 ms | −7% | −8% |
[out:csv(::count)]; nwr(newer:"2026-11-08T00:00:00Z")(43.3,-66.5,47.1,-59.6); out count; |
5,469 / 5,302 ms | −16% | −18% |
nwr(uid:{{UID}})(44.60,-63.66,44.70,-63.52); out meta; |
1,744 / 1,770 ms | −4% | −11% |
[out:csv(::count)]; nwr(uid_touched:{{UID}})(44.60,-63.66,44.70,-63.52); out count; |
1,972 / 1,973 ms | −15% | −16% |
| Sum | 16,063 / 15,732 ms | −11% | −13% |
On top of the code changes: with the all-changes branch (#12, which includes the metadata change in #31), mimalloc still cuts the newer query by 22% (4,308 → 3,381 ms) and the uid_touched query by 14% (1,880 → 1,617 ms). So the allocator gain adds to the code changes rather than overlapping with them.
Memory
| Query | glibc | jemalloc | mimalloc |
|---|---|---|---|
the newer query (history) |
540.5 MB | 549.4 MB | 533.9 MB |
[out:xml]; nwr(44.640,-63.590,44.655,-63.570); (._;>;); out meta; (plain) |
25.6 MB | 29.0 MB | 27.4 MB |
Peak RSS changes by a few MB per query.
How production could use it
- No source change: set
LD_PRELOADforosm3s_queryin the web server or CGI configuration. The query processes are short-lived, so long-running fragmentation behaviour matters less. - Or a build change: link against the allocator (e.g.
../src/configure ... LIBS=-lmimalloc).
Limitations and open questions
- Unknown production platform: the gain depends on the production glibc version and CPU, which are unknown here.
- Dispatcher untested: only
osm3s_querywas tested, notdispatcheror the update tools. - Query mix: the history numbers come from heavy queries; the effect on the real production mix is unknown.
- Narrow test setup: one VM, warm cache, and few runs for the history queries (3 per build).
Generated by Claude Code
Activity