arrow icon indicating copy to clipboard operation
arrow copied to clipboard

[C++] Allocate input buffers with sufficient capacity for SIMDJSON padding

Open Reranko05 opened this issue 2 months ago • 7 comments

Describe the enhancement requested

Parse currently creates a simdjson::padded_string when the input buffer does not have enough capacity for SIMDJSON's required padding. This requires copying the input buffer.

simdjson::padded_string padded_json(reinterpret_cast<const char*>(json->data()),
                                    json->size());
return parse(padded_json);

Investigate whether we can allocate input buffers with enough capacity initially so that this copy can be avoided.

Context: https://github.com/apache/arrow/pull/51038#discussion_r4069610985

Component(s)

C++

Reranko05 avatar Sep 22 '26 16:09 Reranko05

Wait for #51038 to be merged before working on this, if someone wants to contribute.

Reranko05 avatar Sep 22 '26 19:09 Reranko05

I don't think this frames the question correctly. If there is not enough padding in the buffer capacity, then we must copy.

The question is whether we can ensure that we allocate the buffer with enough padding initially, to avoid having to copy later.

pitrou avatar Sep 23 '26 08:09 pitrou

A related question is what happens statistically in real usage. For example, take some real-world JSONL file(s), and determine whether most buffers have enough padding when reading it from Arrow, or not.

pitrou avatar Sep 23 '26 08:09 pitrou

My following comment on a previous PR might also be relevant: https://github.com/apache/arrow/pull/50945#discussion_r3978794379

simdjson::padded_input will provide a (possibly) copy-free version, but it is not yet in a released version:

https://github.com/simdjson/simdjson/commit/85cadf4074b78c7dfa7dabe89bef373b84cf0ba6

taepper avatar Sep 23 '26 08:09 taepper

@pitrou Updated the title and desc, is this fine now?

Reranko05 avatar Sep 23 '26 09:09 Reranko05

Ah, this reframing makes my previous comment mostly obsolete, as it is about allocating sufficiently large buffer sizes in the first place

taepper avatar Sep 23 '26 09:09 taepper

simdjson::padded_input will provide a (possibly) copy-free version, but it is not yet in a released version:

I wonder how that will interact with AdressSanitizer or Valgrind.

pitrou avatar Sep 23 '26 09:09 pitrou