[proxy/json]: optimisations for string escaping#12643
Open
conradludgate wants to merge 9 commits intomainfrom
Open
[proxy/json]: optimisations for string escaping#12643conradludgate wants to merge 9 commits intomainfrom
conradludgate wants to merge 9 commits intomainfrom
Conversation
8855 tests run: 8192 passed, 0 failed, 663 skipped (full report)Flaky tests (2)Postgres 17
Postgres 14
Code coverage* (full report)
* collected from Rust tests only The comment gets automatically updated with the latest test results
ce6bbca at 2025-07-18T10:35:03.965Z :recycle: |
e27a495 to
46d0563
Compare
46d0563 to
a681359
Compare
…we don't need to roundtrip via the CharEscape enum. We also don't need to return the 'rest' slice, we can just insert it into the vec Lastly, we can simplify the hotloop by making write_char_escape cold and moving the vec write inside this fn
… use bytes[..i]. this ends up optimising better
a681359 to
ce6bbca
Compare
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.
I spent some time optimising the string routines. Much of the time in json encoding is spent on strings. We can skip a bunch of that with keys that are statically known to not need escaping. I've also spent some effort optimising the assembly of the string escaping. It's very marginal gains but it's gains nonetheless.
Before:
After:
Frankly, these micro-optimisations are unnecessary but they make me happy 😅
some statistics graphs
Small string
Large string with fmt
Small strings, const escaped vs dynamic escaped.
comparing the assembly for the hot loops
Before
https://godbolt.org/z/vsYqTzv4r
After
https://godbolt.org/z/dsbz7M6WP
I'm gonna attempt to push some of these changes back into serde_json as well.