Skip to content

Commit e709ec7

Browse files
authored
Refactor JSON string writing and escaping logic (#638)
This PR significantly improves JSON response serialization (response projection) performance (50% faster) by replacing the existing character-by-character string escaping logic with a SIMD-accelerated implementation adapted from [sonic-rs](https://github.com/cloudwego/sonic-rs). I also improved `estimate_final_response_size()` with 20% buffer for JSON overhead, that according to the tests I did and responses in the federation audit, is a good estimate. This code is complex and challenging to maintain, due to the low-level SIMD operations, unsafe pointer manipulation, and platform-specific optimizations. However, the previous implementation was also difficult to maintain in its own way. The key advantage here is that we're leveraging battle-tested code from `sonic-rs`, a library we already depend on indirectly.
1 parent 3f78260 commit e709ec7

File tree

5 files changed

+535
-68
lines changed

5 files changed

+535
-68
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
executor: patch
3+
router: patch
4+
---
5+
6+
# Improve JSON response serialization
7+
8+
This PR significantly improves JSON response serialization (response projection) performance (50% faster) by replacing the existing character-by-character string escaping logic with a SIMD-accelerated implementation adapted from [sonic-rs](https://github.com/cloudwego/sonic-rs).

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/executor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ itoa = "1.0.15"
5050
ryu = "1.0.20"
5151
indexmap = "2.10.0"
5252
bumpalo = "3.19.0"
53+
sonic-simd = "0.1.2"
5354

5455
[dev-dependencies]
5556
subgraphs = { path = "../../bench/subgraphs" }

0 commit comments

Comments
 (0)