Hacker News new | ask | show | jobs
by saagarjha 459 days ago
I don't think Python has a particularly optimized bignum implementation.
2 comments

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?