-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The main breaking change that apd/v3 brings is that it no longer uses math/big types directly. There are new wrapper types which avoid allocations in many common cases. See the added calls to MathBigInt and SetMathBigInt. The other breaking change happened in Quo and Sqrt, causing the operations in CUE to end up with different precision: === RUN TestMarshalJSON === RUN TestMarshalJSON/22/a:_1.0/1 types_test.go:2758: got {"a":1.00000000000000000000000}; want {"a":1.0} --- FAIL: TestMarshalJSON (0.00s) --- FAIL: TestMarshalJSON/22/a:_1.0/1 (0.00s) Get the old behavior back by overwriting the Quo and Sqrt methods, running a short piece of code to do what v2 used to do. This makes the unit tests pass again. As a small bonus, whenever we use Quo or Rem on an apd float, the resulting Decimal is now consistently reduced, leaving at least one digit after the decimal point. For example, cue/testdata/resolve/006_arithmetic.txtar worked out "4.0 / 2.0" as "2", but now it is "2.0". Similarly, cue/testdata/basicrewrite/002_arithmetic.txtar worked out "1.0T / 2.0" as "5.0000000000E+11", but now it is "5.0E+11". To properly change the behavior of Quo and Rem across the codebase, internal.BaseContext is now of type internal.Context, which embeds apd.Context. internal.BaseContext is now used everywhere, except for cue/literal, as that would result in cyclic imports. For now that is fine, since that package uses neither Quo nor Rem. If we want cue/literal to use the same custom apd.Context as the rest of the codebase, we could always move internal.Context to avoid the cycle. Performance is largely unchanged; there are likely more gains to be made if we reduce the amount of times we convert to math/big types. goos: linux goarch: amd64 pkg: cuelang.org/go/cue/testdata/benchmarks cpu: AMD Ryzen 7 PRO 5850U with Radeon Graphics │ apd-v2-24 │ apd-v3-24 │ │ sec/op │ sec/op vs base │ /decimal.txtar-8 4.982m ± 1% 5.045m ± 0% +1.27% (p=0.004 n=6) │ apd-v2-24 │ apd-v3-24 │ │ B/op │ B/op vs base │ /decimal.txtar-8 1.873Mi ± 0% 1.872Mi ± 0% -0.09% (p=0.002 n=6) │ apd-v2-24 │ apd-v3-24 │ │ allocs/op │ allocs/op vs base │ /decimal.txtar-8 29.72k ± 0% 29.65k ± 0% -0.22% (p=0.002 n=6) Fixes #1872. Signed-off-by: Daniel Martí <[email protected]> Change-Id: Iadcb4a50f7c9943601a1124570387f62ed65a6f5 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/543421 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Marcel van Lohuizen <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
- Loading branch information
Showing
23 changed files
with
135 additions
and
96 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.