In this article
Record cyclic-GC policy with the timed scope; disabling collection does not remove all allocation or memory-management cost.
The comparison being tested
A Python preprocessing function creates temporary object graphs. Its timeit result looks faster and less variable than the same path in a long-lived serving process. The benchmark temporarily disabled garbage collection during timing. That is a documented measurement choice, but it can omit lifecycle work relevant to the service and change retained state across repeated calls.
The confounding mechanism
Python timeit documents temporary GC disabling by default and allows re-enabling it for measurements where collection matters. Python’s gc interface concerns the collector supplementing reference counting; disabling it does not mean all objects stop being freed or all memory management disappears. A benchmark must name that mechanism rather than treating a GC-disabled result as total real-world allocation cost.
Fix the experimental contract
Define whether the experiment isolates transformation execution or includes the intended object lifecycle. Preserve interpreter version, GC state, object ownership and timed scope. Keep creation and destruction boundaries explicit. Avoid enabling GC only for a slow baseline while excluding it from the candidate. A useful service comparison may need both a controlled microbenchmark and a separately bounded long-lived workload.
A step-by-step comparison
Construct synthetic acyclic and cyclic temporary-object controls with equivalent declared outputs. Observe the selected GC policy before, during and after the test using documented interfaces. Compare timing and retained state under explicit policies without changing the transform itself. Include repeated calls in a controlled process so a favorable first measurement cannot hide accumulating unreachable cyclic objects or later collection work.
Evidence required for the result
Acceptance evidence includes Timer setup, effective GC policy, object-lifetime design, raw timings and memory observations at stated boundaries. Show whether excluded work occurs later or is intentionally outside the question. A lower timed duration is valid only at that scope. Do not interpret collection statistics as a complete allocator or resident-memory account; those measurements describe different mechanisms.
Interpretation and limits
This protocol does not recommend globally disabling collection in serving applications or promise identical behavior across Python releases. Allocation patterns, native extensions and reference ownership can dominate independently. It validates the benchmark’s lifecycle assumption, not the absence of leaks or suitability of a memory policy. Keep correctness and sustained resource behavior separate from one attractive microbenchmark timing.
Primary references and related reading
Record cyclic-GC policy with the timed scope; disabling collection does not remove all allocation or memory-management cost. Python timeit benchmark semantics; Python garbage collector interface.
The proposed investigation of timeit garbage collection policy is not an executed deployment benchmark. Related reading: A GPU inference benchmark you can trust; A hybrid CPU/GPU architecture: splitting an AI service by task.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.