From c17a35592332e349f8a0587ccb0bcd44dcbbac01 Mon Sep 17 00:00:00 2001 From: Antonis Geralis <43617260+planetis-m@users.noreply.github.com> Date: Thu, 28 May 2026 00:31:39 +0300 Subject: [PATCH] Scan until next special char (", \, \0, \c, \L) and append that slice once. (#25498) Benchmark comparison (-d:danger --mm:arc --debugger:native -d:useMalloc, OpenAI file benchmark, 5 runs): - Before: 0.196674934, 0.189423191, 0.198763300, 0.197125584, 0.205015032 - After: 0.182827130, 0.183330852, 0.174878542, 0.174360811, 0.181704921 - Median before: 0.197125584s - Median after: 0.181704921s - Improvement: 7.82% faster Callgrind comparison (same build flags): - Total Ir before: 3,219,477,120 - Total Ir after: 2,449,556,167 - Total Ir reduction: 23.91% parseString hotspot: - Before: 1,343,343,723 Ir - After: 573,423,735 Ir - Reduction: 57.31% (cherry picked from commit f4dd00c4ccfc9791ee21a6d93a18846646613ae6) --- lib/pure/parsejson.nim | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/pure/parsejson.nim b/lib/pure/parsejson.nim index 9292a85964..657f8cc697 100644 --- a/lib/pure/parsejson.nim +++ b/lib/pure/parsejson.nim @@ -175,23 +175,48 @@ proc parseEscapedUTF16*(buf: cstring, pos: var int): int = else: return -1 +proc addSpan(dst: var string; src: string; startPos, endPos: int) {.inline.} = + let n = endPos - startPos + if n <= 0: + return + + let old = dst.len + dst.setLen old + n + + template impl = + for i in 0..