Skip to content

Use On-Demand values in place rather than copying them - #1

Merged
lemire merged 1 commit into
mainfrom
value_in_place
Nov 10, 2026
Merged

lemire merged 1 commit into
mainfrom
value_in_place

Conversation

@lemire

@lemire lemire commented Nov 10, 2026

Copy link
Copy Markdown
Member

Copying a field or a value out of a simdjson_result (std::move(r).get(f)), or passing an sj::value by value, goes through the stack: the compiler writes the fields of the value iterator with an 8-byte and a 4-byte store, then reads them back with a 16-byte load. That load cannot be forwarded from the two stores, so it waits for them (see simdjson/simdjson#3052 and simdjson/simdjson#3061).

We now use the field or the value in place inside its result, after checking the error, and validate() takes its value by reference. No behavior change.

bench_ndjson, one thread, Xeon Gold 6548N, best of 3 interleaved rounds, GB/s (simdjson master):

case GCC 16 clang 21
gharchive, gh schema, validate_skipped 1.933 → 1.938 1.335 → 1.944 (+46%)
gharchive, gh schema, no validation 3.120 → 3.098 3.163 → 3.152
flat, validation 0.731 → 0.742 0.776 → 0.763
gharchive, inferred schema 0.343 → 0.343 0.351 → 0.350

The gh schema reads six fields and validates all the others, which it skips; validate() took its value by value, so every skipped value paid for the stall with clang. With simdjson#3061 alone, clang gets the same gain but GCC 16 loses 4% on this case (1.859 GB/s); with this change on top, GCC 16 is at 1.961 GB/s.

Tests pass with the pinned simdjson 5.0.7 (Apple clang) and against simdjson master, with and without #3061 (GCC 16 and clang 21).

Copying a field or a value out of a simdjson_result, or passing a value
by value, goes through the stack: the compiler writes the fields with
8-byte and 4-byte stores, then reads them back with a 16-byte load that
cannot be forwarded from those stores, so it waits for them. We now use
the value inside the result, and validate() takes a reference.

gharchive.ndjson, gh schema, validate_skipped, one thread, big4:
clang 21: 1.34 -> 1.94 GB/s; GCC 16: 1.93 -> 1.94 GB/s. Other cases
within noise.
@lemire
lemire merged commit 69523bf into main Nov 10, 2026
4 checks passed
lemire added a commit that referenced this pull request Nov 11, 2026
Values are used in place rather than copied (#1): with clang, reading
with a schema and validating the skipped fields is 45% faster. simdjson
5.1.1 makes On-Demand faster with GCC 15 and later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant