Carry the ClickHouse patches onto v4.5.0 - #12
Merged
thevar1able merged 2 commits intoSep 9, 2026
Merged
Conversation
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>
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.
This branch moves the ClickHouse fork of h3 from
v4.4.1to upstream tagv4.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++": sincecoordijk.hbecame header-only upstream,_unitIjkToDigitincrements aDirectionenum in a loop, which is valid C but ill-formed C++, and ClickHouse includes that header from C++ viah3Index.h/faceijk.h. It now iterates with anintand 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.cthe patched_geoAzimuthRadsand_geoAzDistanceRadsno longer exist and have no callers, so upstream's file was kept unchanged.src/h3lib/lib/vec3d.cwas deleted upstream (modify/delete conflict); the file was removed and the_geoToVec3dhunk ported to the header-onlylatLngToVec3insrc/h3lib/include/vec3d.h, using_sincosfor lat and lng and includingmathExtensions.h. The intent of the dropped_geoAzDistanceRadshunk was ported to its replacement path,_hex2dToVec3insrc/h3lib/lib/faceijk.c, by applying_sincosto both the theta and r pairs. ThemathExtensions.hhelper and the_geoToHex2dhunk infaceijk.capplied cleanly.Once merged, ClickHouse's
contrib/h3submodule is bumped to this branch head.