diff --git a/doc/basics.md b/doc/basics.md index b0630063d..b081688b3 100644 --- a/doc/basics.md +++ b/doc/basics.md @@ -1415,6 +1415,8 @@ With this code, deserializing an `std::list` instance would capture only th that are not made by Toyota. +**Performance tip**: You will get better performance if you order the attributes (make, model) +in the order they appear in the JSON document. ### 3. Using static reflection (C++26) @@ -1491,6 +1493,10 @@ void f() { } ``` + +**Performance tip**: You will get better performance if you order the attributes (make, model) +in the order they appear in the JSON document. + #### Special cases However, there are instances where the construction cannot diff --git a/doc/iterate_many.md b/doc/iterate_many.md index f3ec87c9a..2155c5e4c 100644 --- a/doc/iterate_many.md +++ b/doc/iterate_many.md @@ -512,6 +512,9 @@ Otherwise you may use this longer version for explicit handling of errors: } ``` +**Performance tip**: You will get better performance if you order the attributes (make, model) +in the order they appear in the JSON document. + C++26 features (static reflection) ----------------------------------- @@ -662,3 +665,7 @@ for (auto doc : stream) { In every case, the user-defined type (`Car` here) does not need a hand-written `tag_invoke` overload: the library generates the deserialization code from the type's public data members at compile time. + + +**Performance tip**: You will get better performance if you order the attributes (make, model) +in the order they appear in the JSON document. \ No newline at end of file diff --git a/doc/performance.md b/doc/performance.md index 7007d9303..3eb805c5b 100644 --- a/doc/performance.md +++ b/doc/performance.md @@ -208,7 +208,7 @@ You can still make sure of this capability in your code if you are an expert programmer and you are willing to silence sanitizer warnings. If you are building simdjson with C++17 or better, you can use `simdjson::padded_input`. -The `padded_input` struct automatically manages padding for you. It can be constructed from a `std::string_view` or a C-style string with length. If the input already has sufficient padding (up to the end of the memory page), it creates a view without copying. Otherwise, it copies the data into a `padded_string` with proper padding. +The `padded_input` struct automatically manages padding for you. It can be constructed from a `std::string_view`, a C-style string with length, or a `std::string`. For `std::string`, it takes into account the reserved capacity when determining if sufficient padding exists. If the input already has sufficient padding (up to the end of the memory page), it creates a view without copying. Otherwise, it copies the data into a `padded_string` with proper padding. Example usage: @@ -216,6 +216,12 @@ Example usage: std::string_view json = get_json_data(); simdjson::padded_input input(json); // Automatically pads if needed auto result = parser.parse(input); + +// Also works with std::string, considering capacity +std::string json_str = get_json_string(); +json_str.reserve(json_str.size() + 100); // Reserve extra space +simdjson::padded_input input2(json_str); // May avoid copying if capacity is sufficient +auto result2 = parser.parse(input2); ``` This simplifies padding management compared to manually checking and allocating.