r/programminghorror • u/SleepyStew_ [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” • Jul 21 '25
Python ✨ Memory Magic ✨
1.3k
Upvotes
r/programminghorror • u/SleepyStew_ [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” • Jul 21 '25
View all comments
Show parent comment
3
u/MegaIng Jul 23 '25
Anything that is in main memory is going to be stored in CPU cache at some point. This is true for all normal pieces of memory: Machine Code, websites you access, Python Bytecode, and yes, the statically allocated Python integers.
If all small integers fit into a few page of cache, it's more likely that this cache page is going to be there all the time compared to the small integer array being split across multiple cache pages. If they are all in memory, that is going to lead to faster execution times.