mstar.utils.gc_freeze

mstar.utils.gc_freeze#

Move a process’s set-up heap out of the garbage collector’s reach.

A serving process builds a large, long-lived heap while it starts (configs, tokenizers, weights’ Python wrappers, capture buffers). Every gen-2 collection afterwards walks all of it: measured at 200 ms per pass in the API server process, every ~20 s under load, each pass stalling request admission and token delivery for that long. Collecting once and freezing moves those objects to the permanent generation, so later collections only walk what the process created since. Refcounting still frees frozen objects; only a reference cycle alive at the freeze would be retained for good.

Functions

freeze_after_setup(who)

gc.collect() then gc.freeze() for a process that finished its set-up.

mstar.utils.gc_freeze.freeze_after_setup(who)[source]#

gc.collect() then gc.freeze() for a process that finished its set-up. Returns the number of objects frozen.

Parameters:

who (str)

Return type:

int