Hacker News new | ask | show | jobs
by eru 460 days ago
> My rather hasty prototype is actually implemented in Python - not a language you want to do tons of arithmetic in [...]

It might actually not be too bad? The actual big integer arithmetic is written in some fast language, and Python is just the glue holding everything together.

1 comments

I don't think Python has a particularly optimized bignum implementation.
Additionally, it requires allocating memory for every operation. With a mutable bigint type, or fixed-size large integers (e.g. uint256) we could skip a lot of allocation overhead. I have previously prototyped big integer algorithms in Python, and when rewriting to Rust I have gotten massive speedups - there are just so many more opportunities to optimize in Rust/C/C++ than in Python.
Well, it's still better than trying to implement bignums in Python itself on top of limited precision integers.

I'm not even sure whether the prototype in question here uses bignums. Perhaps they use numpy in some clever way (which would probably be a better illustration of my thesis). Or perhaps it's fast enough as it is?