Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
This adds two independent compile-time options for workloads with frequent JSON string escapes or repeated integer shapes. Both are off by default.
SONIC_ENABLE_SERIALIZE_OPTlets AVX2 serialization escape quotes and backslashes in groups within a 32-byte block. Blocks that need control-character or emoji escaping use the existing escape handler. The option also exposesWriteBuffer::ReleaseBuffer()for transferring ownership andSerializeFlags::kSerializeWriterStringGrowthfor callers that want more headroom when writing large strings.SONIC_ENABLE_PARSE_UINT_FASTPATHhandles one- and two-digit unsigned object values and 16-digit unsigned array elements immediately followed by a delimiter. Other number shapes use the existing parser. Raw-integer parsing and SAX termination retain their existing behavior and offsets.Benchmark
Median CPU time per document over nine runs of the repository's
Encode_SonicDynandDecode_SonicDynbenchmarks. Lower is faster. Each run was pinned to one logical CPU on an Intel Xeon Platinum 8582C (Linux x86-64 VM). The three binaries ran in rotating order, using Google Benchmark 1.9.5 with a minimum of 0.15 seconds per case. Builds used Clang 20.2.0, C++17,-O3 -DNDEBUGand static AVX2 (-mavx2 -mpclmul -mbmi -mlzcnt). The baseline is3ecbef2. All encode timings use the default serialization flags.The largest gains were on inputs that repeatedly hit the new paths. Enabling the macros on the PR reduced dense-escape encoding from 231.78 to 20.59 µs, while four-digit object values took 6.9% longer (57.13 to 61.10 µs). Against master, the three repository JSON files ranged from 0.3% faster to 2.2% slower.
Reproduce the timing runs on Linux x86-64
From the PR checkout, build the existing benchmark against each header version. On systems with GCC 8's libstdc++, also pass
-DCMAKE_CXX_STANDARD_LIBRARIES=-lstdc++fsto CMake.Optional writer growth
With
SONIC_ENABLE_SERIALIZE_OPTdefined, appending two newline-filled strings (1 MiB, then 1.25 MiB) produced byte-identical 4,718,599-byte JSON arrays. The measuredWriteBuffer::Capacity()after each string was 9,437,238 → 18,874,476 bytes with ordinary append, and 11,796,547 → 11,796,547 bytes with the extra growth flag. In this example, reserving 2.25 MiB more for the first string avoided a second buffer growth and reduced the final reserved capacity by 6.75 MiB.Reproduce the writer-capacity comparison
Validation