You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[mypyc] Speed up generator allocation by using a per-type freelist (#19316)
Add support for per-type free "lists" that can cache up to one instance
for quick allocation.
If a free list is empty, fall back to regular object allocation.
The per-type free list can be enabled for a class by setting a flag in
ClassIR. Currently there is no way for users to control this, and these
must be enabled based on heuristics.
Use this free list for generator objects and coroutines, since they are
often short-lived.
Use a thread local variable for the free list so that each thread in a
free threaded build has a separate free list. This way we need less
synchronization, and the free list hit rate is higher for multithreaded
workloads.
This speeds up a microbenchmark that performs non-blocking calls of
async functions in a loop by about 20%. The impact will become
significantly bigger after some follow-up optimizations that I'm working
on.
This trades off memory use for performance, which is often good. This
could use a lot of memory if many threads are calling async functions,
but generally async functions are run on a single thread, so this case
seems unlikely right now. Also, in my experience with large code bases
only a small fraction of functions are async functions or generators, so
the overall memory use impact shouldn't be too bad.
We can later look into making this profile guided, so that only
functions that are called frequently get the free list. Also we could
add a compile-time flag to optimize for memory use, and it would turn
this off.
0 commit comments