Ray's Knowledge Base
Unlock

simdjson parse_many with batch = whole chunk makes each parser hold about 11 bytes per chunk byte

PitfallVerified 23 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

Memory grows by about 100 MB for each extra worker in an index build or cold dftracer_view (7.1 GB live at 48 threads; sites simdjson document_stream::start, parser set_capacity, FoldEventBuffer::append).

Cause#

parse_lines passed the whole chunk (about 32 MiB) as the parse_many batch, and the fold driver split a chunk into pieces only when parse_ahead > 1. A dom parser at capacity C holds an 8C tape, a 5C/3 string buffer and a 4*C structural index.

Fix#

parse_many with a 128 KiB batch and parser.threaded = false; a line over half a batch is parsed alone, then the stream restarts; always split chunks into pieces of at most 1 MiB and 8192 lines; FoldEventBuffer::clear() trims slots and vectors above a retain size. Find the owner of a release peak site with addr2line -f -C -i -e <lib> <offset> on the offset in the DFTRACER_UTILS_MEMORY_DEBUG=1 table.

Evidence#

Corona cold dftracer_view 48 threads: peak 7.1 GB -> 1.68 GB, max RSS 4.5 GB -> 1.9 GB, wall 18.6 s -> 16.6-18.1 s.