-
In my use case it's difficult to pad the json without allocating a new buffer and copying to it, but my application is performance-critical so the allocation overhead is significant. So the questions are:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
Do you control the initial allocation of the buffer you read your JSON into, and can you pad that initial allocation a bit to match? There isn't currently a great workaround -- you can use the fallback parser but it doesn't use simd and is slower. There are a couple of reasons we need padding, but one important reason is that we can do faster string processing by reading 8-64 bytes at a time, including when we are at the end of the string (we just retroactively cap the string when we find the end quote). |
Beta Was this translation helpful? Give feedback.
-
It is safe as long as the end of the string is at least |
Beta Was this translation helpful? Give feedback.
-
Thank you both for the explanation! I have another question that could use your help: I can mitigate my problem by switching to a faster allocator for the padded string (but other allocations in the parser are still std So the code without those auto doc = parser.iterate(m_compressedPadded, m_compressedLength, m_compressedLength); The code with auto doc = parser.iterate(m_compressedPadded, m_compressedLength, m_compressedLength + SIMDJSON_PADDING); What am I doing wrong here? |
Beta Was this translation helpful? Give feedback.
-
Please see... I provide a complete example. |
Beta Was this translation helpful? Give feedback.
Do you control the initial allocation of the buffer you read your JSON into, and can you pad that initial allocation a bit to match?
There isn't currently a great workaround -- you can use the fallback parser but it doesn't use simd and is slower. There are a couple of reasons we need padding, but one important reason is that we can do faster string processing by reading 8-64 bytes at a time, including when we are at the end of the string (we just retroactively cap the string when we find the end quote).