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

Sharing an optimization idea for Decimal operations #308

Open
gyson opened this issue Jan 17, 2023 · 4 comments
Open

Sharing an optimization idea for Decimal operations #308

gyson opened this issue Jan 17, 2023 · 4 comments

Comments

@gyson
Copy link

gyson commented Jan 17, 2023

we use this decimal library at production and it works really well for last a few years.

The only minor complain is that some times (during profiling) we noticed that some operations are slow (e.g. sql serialization and multiplication). Most of slowness is from big.Int related operations. Therefore, we tried an approach to optimize (our) common cases by represent decimal numbers with int64 instead of big.Int and this resulted 5x to 100x speedup.

We'd like to share our result and made our approach open-sourced as well: https://github.com/alpacahq/alpacadecimal


this is to share an optimization idea that maybe works for others.

this is not an issue. be free to close it.

@langurs
Copy link

langurs commented Mar 3, 2023

Nice. Does it account for overflow/underflow on addition/subtraction? What about other operations? Does it switch to using big.Int when necessary?

@eapenkin
Copy link

I too encountered this problem. However, I utilized uint64 for storing the coefficient. Consequently, a decimal can't have more than 19 digits. It is more than enough for monetary calculations.

https://github.com/govalues/decimal
https://github.com/govalues/money

@mwoss
Copy link
Member

mwoss commented Apr 7, 2024

Hi @gyson, @eapenkin! :D Thanks for your amazing work and for making those libraries available to everyone. They look quite promising :D In PR #363 I've introduced a new docs section Alternative libraries when I've briefly mentioned your work. Please take a look and let me know if you are happy with such a description :D

@eapenkin
Copy link

eapenkin commented Apr 8, 2024

Hello @mwoss, thank you for the recognition! The description in PR #363 looks good to me. Your effort to include my work is greatly appreciated.

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

No branches or pull requests

4 participants