Repository navigation
perf: compute latLngToVec3 with math.Sincos in x/h3go - #156
Merged
Merged
Conversation
latLngToVec3 took the sine and cosine of both the latitude and the longitude
through four separate math.Sin / math.Cos calls, range-reducing each angle
twice. math.Sincos returns sine and cosine from a single reduction, so the
forward projection now makes two calls instead of four.
The projected output is unchanged: the pinned known-value tests, the cgo parity
suite and the conformance suite all still pass, and the path stays
allocation-free. latLngToVec3 is unexported, so unlike the other benchmarks it
cannot be reached from paritytest; BenchmarkLatLngToVec3 is added in-package to
guard it.
benchstat, fifteen interleaved rounds of each side on an Apple M3 Max:
│ old │ new │
│ sec/op │ sec/op vs base │
LatLngToVec3-16 13.750n ± 1% 8.614n ± 4% -37.35% (p=0.000 n=15)
End to end the win is small, around 1% off LatLngToCell, since the projection is
well under a tenth of that call, which is dominated by the face-IJK descent.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Coverage Report for CI Build 37078028382Coverage remained the same at 100.0%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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.
What
latLngToVec3took the sine and cosine of both the latitude and the longitude through four separatemath.Sin/math.Coscalls, range-reducing each angle twice.math.Sincosreturns sine and cosine from a single reduction, so the forward projection now makes two calls instead of four.Discovered by #137
Why it's safe
x/h3go/paritytest), and the conformance suite all still pass.Results
latLngToVec3is unexported, so unlike the other benchmarks it can't be reached fromparitytest;BenchmarkLatLngToVec3is added in-package to guard it.benchstat, fifteen interleaved rounds of each side on an Apple M3 Max:
End to end the win is small — around 1% off
LatLngToCell— since the projection is well under a tenth of that call, which is dominated by the face-IJK descent.🤖 Generated with Claude Code