A synthetic .pfw.gz written with gzip.open is one member, so a reader holds the whole file
PitfallVerified 8 Oct 2026Holds project: dftracer-utils
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
Peak RSS barely changes when you lower --memory-budget on a generated trace tree (1390 MiB at 4GB, 1068 MiB at 128MB for 4M calls).
Cause#
async_streaming_gz_lines decodes one gzip member at a time. Python gzip.open(...).write(...) makes one member for the whole file, so each reader holds a full decoded file.
Fix#
Write many small members: build blocks of lines and write gzip.compress(block, 1) back to back into one binary file (30000 lines per member). Re-measure with /usr/bin/time -l (macOS) or memory.peak (cgroup).
Evidence#
Same data in small members: 587, 299, 173 and 91 MiB at 4GB, 256MB, 128MB and 64MB, with identical output (same md5).
Also found by searching
- peak memory does not follow --memory-budget in a synthetic trace test
- async_streaming_gz_lines holds the whole file in memory
- python gzip.open one member trace too big