Recently, I was going through the source code of Python and found something really interesting ⚡
Python caches small integers to keep its runtime efficient 🤯 Given that all programs are more likely to use smaller integers Python during its boot loads an array with all small integers.
Whenever someone refers to a small integer, instead of allocating a new object, Python returns the reference to the existing one. This dramatically reduces the number of heap allocations and keeps the runtime efficient.
I have written a detailed write-up about it on Duggup going in-depth of all the nuances and references in CPython source code.
Read - https://lnkd.in/gV7-c6Ac
If you know any interesting trick that Python employs to make things efficient, do share it on Duggup.
⚡ I keep writing and sharing these engineering nuggets, so if you are keen on learning them, follow along.
arpitbhayani.me/courses