Repository navigation
Use On-Demand values in place rather than copying them - #1
Merged
Merged
Conversation
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
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.
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.
Copying a field or a value out of a
simdjson_result(std::move(r).get(f)), or passing ansj::valueby 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):ghschema,validate_skippedghschema, no validationThe
ghschema 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).