Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to fix from_str overflow rounding #454

Closed
wants to merge 5 commits into from

Conversation

chris-cantor
Copy link

@chris-cantor chris-cantor commented Dec 29, 2021

resolves #453

The culprit is the rounding behaviour prevented it from overflowing, and ended up returning an Ok in the end. The fix is: we should not attempt to round a number before the decimal point.

Having read through the code, I think there are opportunities to make parse_str_radix_10 faster & simpler, e.g. removing the coeff ArrayVec and doing it in one pass; using 128 bit integer arithmetic etc.

I wonder what is your view on this?

@chris-cantor chris-cantor force-pushed the issue/453 branch 2 times, most recently from 0bb52d3 to 9c51e7d Compare December 29, 2021 14:05
Chris added 2 commits December 29, 2021 22:11
cargo bench --bench lib_benches -- decimal_from_str

Baseline:
test decimal_from_str        ... bench:         566 ns/iter (+/- 21)

Current:
test decimal_from_str        ... bench:         290 ns/iter (+/- 12)
cargo bench --bench lib_benches -- decimal_from_str

Baseline:
test decimal_from_str        ... bench:         566 ns/iter (+/- 21)

Current:
test decimal_from_str        ... bench:         193 ns/iter (+/- 1)
@chris-cantor
Copy link
Author

chris-cantor commented Dec 29, 2021

I tried to remove the coeff ArrayVec and perform calculation in a one pass.
Fixed the issues and coincidentally performance seemed to improve quite a bit!

Here is the relevant bench on my M1 Pro:

cargo bench --bench lib_benches -- decimal_from_str

master:
test decimal_from_str        ... bench:         566 ns/iter (+/- 21)

7289df8:
test decimal_from_str        ... bench:         193 ns/iter (+/- 1)

All checks seem to pass now https://github.com/cantortrading/rust-decimal/actions/runs/1634285353

@chris-cantor
Copy link
Author

Closed in favour of #455

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

from_str rounding issues when overflow from too many digits
1 participant