Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I like this feature of python, but it's wise to remember that operations that we typically think of as O(1) are actually usually dependent on the length of the input, so allowing arbitrary length integers can cause issues (such as DOS opportunities) in places some people don't think to look. Specifically, Python recently changed the str -> int conversion logic to error on strings beyond a certain length (e.g. `int('1'*4301)` will error.) [1]

[1] https://news.ycombinator.com/item?id=32753235



They’re also much more expensive in memory, because you have to separately allocate anything you don’t know the size of.

Something being O(N) can also be a security issue since it introduces a timing side channel.

I don’t think I’ve ever needed a bignum in my life or even a 64-bit integer (excluding pointers and file sizes). Of course I’ve used them inside black box crypto libraries but they have to be careful with them because of said security issues.


As implemented in lisps they typically don't use more memory than 64 bit longs. That's because fixnums (typically 61 bit signed values) are unboxed, existing in the "pointer" itself; only when numbers fall outside that range do they become bignums that must be heap allocated (and in practice almost all integers are fixnums.)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: