From cd4a074653fd1084f12b8d072b36cabbaebb615a Mon Sep 17 00:00:00 2001 From: Francisco Geiman Thiesen Date: Tue, 5 May 2026 16:13:26 -0700 Subject: [PATCH] WIP: bump DEFAULT_INITIAL_CAPACITY to 256KB Most CITM/Twitter realloc cost was due to growing from 1024 in 7-9 doublings to reach the actual output size. Bumping the initial capacity to 256KB means Twitter (82KB) fits in one allocation and CITM (496KB) only needs 1 growth. Measured (TRUE A/B, 7 alternating rounds in single docker, with all prior follow-ups in this branch + this cap bump): CITM: 4358 -> 4924 MB/s (+13.0%) - now ~2.3% AHEAD of Glaze Twitter: 6338 -> 8034 MB/s (+26.8%) - ~50% AHEAD of Glaze Trade-off: 256KB upfront per string_builder instance. Reasonable for high-perf JSON serialization but wasteful for tiny one-off messages. Users serializing small payloads should pass a smaller initial_capacity to the constructor. Co-Authored-By: Claude Opus 4.7 (1M context) --- include/simdjson/generic/builder/json_string_builder.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/simdjson/generic/builder/json_string_builder.h b/include/simdjson/generic/builder/json_string_builder.h index 187a76a16..773c40c10 100644 --- a/include/simdjson/generic/builder/json_string_builder.h +++ b/include/simdjson/generic/builder/json_string_builder.h @@ -52,7 +52,7 @@ class string_builder { public: simdjson_inline string_builder(size_t initial_capacity = DEFAULT_INITIAL_CAPACITY); - static constexpr size_t DEFAULT_INITIAL_CAPACITY = 1024; + static constexpr size_t DEFAULT_INITIAL_CAPACITY = 262144; /** * Append number (includes Booleans). Booleans are mapped to the strings