JSON Protocol String & Base64 optimization for ARM #632
+933
−49
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.
This PR optimizes String Decoding & Encoding and Base64 Decoding & Encoding in JSONProtocol and SimpleJSONProtocol.
General performance problem was (on both x86 and ARM) that the compiler only generates single-byte load and store instructions for folly IOBuf writes and reads, which limits the achieved throughput. Our optimizations target large inputs. Evaluation was performed with
ProtocolBench
from this project.String encoding:
Vectorizing this loop is difficult as each character produces one or two output characters, depending on whether it needs to be escaped.
We optimized this for the case that characters that need to be escaped occur infrequently. We unroll the loop by a factor of 16 and use ARM NEON intrinsics to load 16 consecutive chars in each iteration. We then check with vector comparisons if any character requires escaping. If no escaping is required, we immediately copy the 16 B chunk to the output. If at least one character in an 8 B chunk requires escaping, we escape every char in that chunk in a char-by-char fashion.
String decoding:
Base64 encoding:
Base64 decoding:
Performance data was collected with fbthrift and folly being compiled with the flags: "-mcpu=neoverse-v2+crypto+sve2-sm4+sve2-aes+sve2-sha3"
This PR is contributed by NVIDIA.