Hacker News new | ask | show | jobs
by lbolla 2047 days ago
I discovered a similar trick few years ago: https://stackoverflow.com/questions/35660899/reduce-memory-f...

The idea is to tweak when `mmap` or `malloc` are used by the Python interpreter. One allows memory to be released to the OS right away, whereas the other is not.

It is a useful trick if your application is generating lots of small objects.

2 comments

Keep in mind that’s from Python 2.5. Modern Python uses arenas that always use mmap.
I developed that tweak for Python 2.7 and I am running in production with Python 3.6. I tested with later Python versions, too.

Do you have some pointers about arenas always using mmap? I'd like to know how that trick can work if that was the case.

It doesn't work, that's their point. With modern python versions those env variables do next to nothing. It won't crash your python but it also won't help you.
My point is that it does work. I tested with Python 2.7 and Python 3.6+.
That's a neat trick and even simpler than what I wrote about.