4 ms·
Even if you manage to preload everything you need, Python's reference counting mechanism will cause everything to be copied anyway. Every time you access an ob
by cakoose 7y ago
Even if you manage to preload everything you need, Python's reference counting mechanism will cause everything to be copied anyway.
Every time you access an object, its reference count is mutated, which will the memory page to be copied.
There are workarounds if you're willing to mess with the Python interpreter: https://instagram-engineering.com/copy-on-write-friendly-python-garbage-collection-ad6ed5233ddf https://instagram-engineering.com/copy-on-write-friendly-pyt...
- lozenge 7y agogc.freeze() reached Python 3.7 as mentioned there, I'm not sure how many web frameworks are using it though.
- ghostwriter 7y ago> Python's reference counting mechanism will cause everything to be copied anyway. isn't it CPython specific though, and may not be observed when running on PyPy?
- dfox 7y agoIt is. And in practice it is far from everything, only stuff that is actively directly referenced by the service code.
- pas 7y agoIt still helps with the loaded .so files and whatnot. The code objects and other things that are immutable. (CPython refcounts those too?)
- pdonis 7y ago> The code objects and other things that are immutable. (CPython refcounts those too?) CPython refcounts all objects. Refcounting is not required because of mutability; it's required because the interpreter needs to know when an object's memory can be reclaimed for something else. I don't know if code objects specifically would have their refcounts mutated a lot, since typically they're only referenced by one object, the function that they're the code for. But function objects will have their refcounts mutated every time the function is called, since that sets up a stack frame that grabs a reference to the function object and then releases it when the function returns.
- rcxdude 7y agoThe code and read-only data of .so files will be shared anyway