fallintoplace opened a new pull request, #2129: URL: https://github.com/apache/iceberg-go/pull/2129
**What** - Speed up decimal truncation. **Why** - `big.Int.Mod` already returns a non-negative remainder for positive widths. - The extra add and modulus cost two allocations per call. - Prebound transforms are 18% to 38% faster in these benchmarks. <details> <summary>Full benchmark results (16 cases)</summary> Apple M1 Pro, Go 1.26.3, one CPU. Medians of 7 runs at 1s per case. The benchmark file from this PR was used for both revisions. | Case | ns/op before -> after | Time change | B/op before -> after | Allocs/op before -> after | | --- | ---: | ---: | ---: | ---: | | Bucket/Apply | 35.44 -> 35.91 | no significant change | 16 -> 16 | 1 -> 1 | | Bucket/Transformer | 30.53 -> 31.27 | no significant change | 16 -> 16 | 1 -> 1 | | Truncate/zero/Apply | 243.6 -> 234.8 | -3.61% | 208 -> 192 | 11 -> 9 | | Truncate/zero/Transformer | 133.4 -> 82.97 | -37.80% | 88 -> 72 | 5 -> 3 | | Truncate/positive/Apply | 284.8 -> 248.1 | -12.89% | 264 -> 208 | 13 -> 11 | | Truncate/positive/Transformer | 174.7 -> 118.5 | -32.17% | 144 -> 88 | 7 -> 5 | | Truncate/negative/Apply | 299.9 -> 258 | -13.97% | 264 -> 208 | 13 -> 11 | | Truncate/negative/Transformer | 184.4 -> 130.7 | -29.12% | 144 -> 88 | 7 -> 5 | | Truncate/wide-positive/Apply | 321.7 -> 270.1 | -16.04% | 304 -> 248 | 13 -> 11 | | Truncate/wide-positive/Transformer | 202.8 -> 156.1 | -23.03% | 184 -> 128 | 7 -> 5 | | Truncate/wide-negative/Apply | 268.7 -> 256 | -4.73% | 256 -> 240 | 12 -> 10 | | Truncate/wide-negative/Transformer | 156.9 -> 129 | -17.78% | 136 -> 120 | 6 -> 4 | | Truncate/width-1/Apply | 273.5 -> 245.9 | -10.09% | 230 -> 214 | 11 -> 9 | | Truncate/width-1/Transformer | 142.4 -> 100.2 | -29.63% | 110 -> 94 | 5 -> 3 | | Truncate/width-max/Apply | 330.8 -> 260.3 | -21.31% | 281 -> 233 | 12 -> 10 | | Truncate/width-max/Transformer | 203.8 -> 148.5 | -27.13% | 161 -> 113 | 6 -> 4 | All 14 truncation cases improved (p <= 0.026), with two fewer allocations each. Both bucket controls showed no significant time change (Apply p=0.805, Transformer p=0.154). ```sh go test . -run '^$' -bench '^Benchmark(Bucket|Truncate)TransformDecimal$' -benchmem -benchtime=1s -count=7 -cpu=1 ``` Base: `0b0828bffd8ba7f50e18cbafa59d6a4b8e5df2f6` Head: `6436082bce1a0da032ff5e9a9931535c3be3cb64` </details> **Implementation** - Remove the extra add and second modulus. - Keep rounding for negative values and preserve decimal scales. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
