PERFORMANCE Signal 414
C++ markdown parser AST nodes shrunk from 232 bytes to 16 bytes via pointer compression and arena allocation
A developer porting a Rust markdown parser to C++ reduced per-node memory from 232 bytes to 16 bytes using arena allocation, compressed string pointers, in-place arena string growth, and struct field packing.
AST-based markdown parsers pay per-node overhead for every field regardless of node type, so node size directly drives memory consumption on large documents. The techniques shown, arena allocation, 32-bit pointer offsets, and in-place string growth, are transferable to any C++ project that builds large in-memory trees with uniform lifetime. The benchmarks show up to 75% memory reduction on entity-heavy input with no speed regression measured.
Written by elseif from the cluster below · every claim links back to a sourceThe three things worth knowing
Compressing string pointers from 8 bytes to 4-byte arena offsets cut per-node overhead by 64 bytes, dropping nodes from 232 to 168 bytes.
Growing the last arena-allocated string in place eliminated dead copies from repeated allocations, cutting entity-heavy memory usage by 73.8%.
Reordering struct fields and packing bools reduced padding waste, contributing to the final 16-byte node size.
THE CLUSTER
↗