Generally per-level or at some other temporal division. That, in-place loading and fixed-size pools for things like effects covered 90% of the allocation tricks we did to get huge performance gains.
[1] https://developers.google.com/protocol-buffers/docs/referenc...
My allocator isn’t included as it is part of a class project, but you can make your own malloc pretty easily.
Alternatively you can just do some LD preload magic, but I don’t know much about that (and this was needed to match the class spec)
Was this a class that you took, or one that you TA or tutored?
This suggests that Python's pool allocator is really bad at handling start up procedures, doesn't it?
It intentionally over allocates, but not by enough to handle the warm up procedure.
It does make sense CPython is tuned more towards runtime than startup time. One is a continual cost, one is paid once and doesn't matter for a large variety of workloads.
But if CPython really is make 1000+ allocations during startup, then it is probably going to fragment badly, which slow down everything, and into the future as well...
Seems that's not a crazy idea. [0] Zapier linked CPython to jemalloc which tends to fragment less and saw 40% memory gains.
I guess if you took the time to tune jemalloc to your workload you should be able to see significant performance improvements at startup as well as in the hot path.
cf. https://github.com/pypa/setuptools/issues/510
The problem is so bad that it's one of the top quoted reasons that hg is considering a gradual rewrite to rust:
Though it looks like it's more about supplying a way to embed hq in a proprietary (or non-Python) application via subprocess communication rather than directly importing the GPL modules or having to string-parse responses. There doesn't seem to be provision for interacting with the server directly from the command line, which is odd, since this pattern is well established from Java land (bazel, for example).
I'm aware of yapsy as a lightweight plugin system, but entry_points really is the gold standard in terms of Python extensibility. It's a shame it can't be made more performant.
Edit: to be clear, I’m pretty sure that initial block could be reserved on the heap. The benefit comes from the large initial allocation, not from the memory being on the stack.