Skip to content

Carry the ClickHouse patches onto v4.5.0 - #12

Merged
thevar1able merged 2 commits into
ClickHouse:ClickHouse/v4.5.0from
actueleai:ClickHouse/v4.5.0
Sep 9, 2026
Merged

thevar1able merged 2 commits into
ClickHouse:ClickHouse/v4.5.0from
actueleai:ClickHouse/v4.5.0

Conversation

@actueleai

Copy link
Copy Markdown

This branch moves the ClickHouse fork of h3 from v4.4.1 to upstream tag v4.5.0. It carries Alexey Milovidov's "Speed up geo coordinate transforms: combined sincos + fewer trig calls" (cherry-picked with -x, original author preserved) plus one new fork patch, "Make coordijk.h compile as C++": since coordijk.h became header-only upstream, _unitIjkToDigit increments a Direction enum in a loop, which is valid C but ill-formed C++, and ClickHouse includes that header from C++ via h3Index.h/faceijk.h. It now iterates with an int and casts back, behaviour unchanged; this is upstreamable. No patch was dropped as a whole.

Two hunks of the sincos patch became obsolete because upstream refactored the indexing code (uber#1145/uber#1154/uber#1155). In src/h3lib/lib/latLng.c the patched _geoAzimuthRads and _geoAzDistanceRads no longer exist and have no callers, so upstream's file was kept unchanged. src/h3lib/lib/vec3d.c was deleted upstream (modify/delete conflict); the file was removed and the _geoToVec3d hunk ported to the header-only latLngToVec3 in src/h3lib/include/vec3d.h, using _sincos for lat and lng and including mathExtensions.h. The intent of the dropped _geoAzDistanceRads hunk was ported to its replacement path, _hex2dToVec3 in src/h3lib/lib/faceijk.c, by applying _sincos to both the theta and r pairs. The mathExtensions.h helper and the _geoToHex2d hunk in faceijk.c applied cleanly.

Once merged, ClickHouse's contrib/h3 submodule is bumped to this branch head.

alexey-milovidov and others added 2 commits September 9, 2026 21:26
The lat/lng <-> H3 cell transforms are dominated by transcendental
function calls. Several hot routines computed sin(x) and cos(x) of the
same angle with two separate library calls, and a few recomputed the
same value more than once:

  * _geoToVec3d       - sin/cos of the latitude and of the longitude
  * _geoAzimuthRads   - sin/cos pairs; cos(p2->lat) was evaluated twice
  * _geoAzDistanceRads- sin/cos of p1->lat, the distance and the azimuth
                        were each evaluated twice
  * _geoToHex2d       - sin/cos of theta

Compute each sin/cos pair together via a small _sincos() helper (it
lowers to a single libm `sincos` call where available and falls back to
separate sin()/cos() otherwise) and reuse already-computed values. The
outputs are bit-for-bit identical; this only removes redundant work.

Measured on 10M rows (clang -O3, no LTO):

  cellToLatLng     +9..11%
  cellToBoundary   +14%
  cellArea         +8%
  latLngToCell     +3..4%

All 311 existing tests pass unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit e38f58e)
Since v4.5.0 (uber#1154) coordijk.h is header-only and its inline
functions are compiled by every translation unit that includes it,
including C++ ones: ClickHouse includes h3Index.h (and hence faceijk.h
and coordijk.h) from src/Functions/h3GeometryToCells.cpp.

The loop in _unitIjkToDigit incremented a variable of enum type
Direction. That is valid C but ill-formed in C++ ("cannot increment
expression of enum type 'Direction'"). Iterate with an int and cast the
result back to Direction instead. Behaviour is unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@thevar1able
thevar1able merged commit a5625fa into ClickHouse:ClickHouse/v4.5.0 Sep 9, 2026
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.

3 participants