rippled icon indicating copy to clipboard operation
rippled copied to clipboard

Number merge

Open HowardHinnant opened this issue 3 years ago • 9 comments

High Level Overview of Change

Use Number for IOUAmount and STAmount arithmetic

* Guarded by amendment fixUniversalNumber
* Produces slightly better accuracy in some computations.

Context of Change

There are two many decimal floating point classes in rippled, and AMM needed a third. This merges common code. A side effect is that some transaction arithmetic becomes more accurate in the final digit or two. Therefore this change is guarded by an amendment.

The first many commits introduce Number. Only the final commit merges the common code with IOUAmount and STAmount, and introduces the amendment.

Type of Change

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [x] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [x] Refactor (non-breaking change that only restructures code)
  • [ ] Tests (You added tests for code that already exists, or your new feature included in this PR)
  • [ ] Documentation Updates
  • [ ] Release

Test Plan

Some tests are updated with the slightly more accurate results.

HowardHinnant avatar Jun 02 '22 16:06 HowardHinnant

这个是关于ripple还是radar?

zhangdongwei123 avatar Jun 24 '22 04:06 zhangdongwei123

@zhangdongwei123, this repository is for the XRP Ledger and has nothing to do with radar.

scottschurr avatar Jun 24 '22 15:06 scottschurr

雷达还开吗?

zhangdongwei123 avatar Jun 24 '22 23:06 zhangdongwei123

@zhangdongwei123, you are asking at the wrong site. This site has no connection with radar. We don't know whether radar is working or not. Please find somewhere else to ask.

scottschurr avatar Jun 25 '22 00:06 scottschurr

@HowardHinnant I'm seeing two unit tests fail (the first is this one: #2 failed: Taker_test.cpp(238)) I haven't dug into what that test is doing, but I wanted to make a note before I dug into the code.

seelabs avatar Jun 29 '22 15:06 seelabs

Looking into it now, thanks.

HowardHinnant avatar Jun 29 '22 15:06 HowardHinnant

This new commit fixes the failures you observed @seelabs. For reasons that are not clear to me, the Taker test ran with the amendment on in non-unity build, and with the amendment off in unity build. The patch forces the amendment on in the Taker test for both non-unity and unity builds.

HowardHinnant avatar Jul 19 '22 20:07 HowardHinnant

Rebased to 1.9.2-rc1.

HowardHinnant avatar Jul 20 '22 00:07 HowardHinnant

Rebased to 1.9.2.

HowardHinnant avatar Aug 15 '22 21:08 HowardHinnant

For posterity, some notes re: 6c8d3abfb1d27dab7a03556ea943c5084e892311

I've tested on two versions of macOS: 10.14 and 13.2. The patch replaces the use of __udivti3 within the Number multiplication operator. I tested for correctness on over 55 quintillion values of uint128_t, which is a tiny fraction of the total values that this type can hold. I concentrated the tests at and near 0, around the transition between the upper 64 bits going from zero to non-zero, and at and near the maximum value of uint128_t. These tests were not included with the patch because they would be far too time consuming for --unittest. I also tested for performance on both macOS 10.14 and 13.2. On 10.14 the patch is a little over 30x faster than __udivti3. But on 13.2 it is the exact same speed. Not because the patch is slower, but because __udivti3 is that much faster on 13.2 (for the divide by a constant 10 case). I do not know if the linux gcc tools have implemented such an optimization or not. So this may or may not improve the performance of Number::operator*= on linux. Although it will definitely eliminate the call to __udivti3.

Internal testing:

[We are] very pleased with the results. For one of the consensus phase I picked, it used to take 3051ms to apply 458 transactions before the fix but now it only took 1063ms to apply 475 transactions to the ledger.

We observed both have a ~ 3.6 better performance than previous build. ... Submit response time also reduced significantly as well.

intelliot avatar Feb 03 '23 00:02 intelliot

Just needs conflicts to be resolved @HowardHinnant . There is no need to rebase (although that is fine if that's what you prefer) - merge commits are OK since they will be squashed anyway.

intelliot avatar Feb 07 '23 18:02 intelliot

Squashed and rebased to Develop (1.10.0-rc1). Builds and passes --unittest.

HowardHinnant avatar Feb 07 '23 20:02 HowardHinnant