hcrosse opened a new pull request, #1520:
URL: https://github.com/apache/arrow-go/pull/1520
### Rationale for this change
`MaxPrecision[T]()` recomputes a fixed value with `math.Pow` and
`math.Log10` on every call, about 16 ns, and `Decimal32FromFloat` and
`Decimal64FromFloat` call it for every value. Returning the literals is simpler
to check and lets the call inline.
### What changes are included in this PR?
`MaxPrecision[T]()` returns 9, 18, 38 or 76 by type width.
`Decimal32FromFloat` and `Decimal64FromFloat` benefit per value, including when
their builders parse JSON numbers. `Decimal32.Rescale` and `Decimal64.Rescale`
benefit only when scales differ and the value is nonzero. `NewDecimalType` and
`NarrowestDecimalType` benefit once per call.
On an Apple M4 Max with 14 cores, macOS arm64 and Go 1.26.10, I measured ten
interleaved samples per version:
```text
before ns/op after ns/op change
MaxPrecisionConcrete 16.455 ± 5% 1.148 ± 17% -93.02%
MaxPrecisionGeneric 15.5950 ± 3% 0.7817 ± 14% -94.99%
Decimal64FromFloat 19.685 ± 3% 3.882 ± 20% -80.28%
Decimal64Rescale 18.885 ± 5% 2.138 ± 15% -88.68%
NewDecimalType 27.245 ± 5% 7.793 ± 8% -71.40%
NarrowestDecimalType 59.060 ± 13% 7.215 ± 17% -87.78%
```
### Are these changes tested?
`arrow`'s existing `TestNewDecimalTypeValidatesPrecision` and
`TestNarrowestDecimalType` check all four values.
Vet, `-race -tags assert,test` tests, lint, the Release Audit Tool and
targeted `GOARCH=386` tests passed.
### Are there any user-facing changes?
None. There is no API change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]