Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(types): serialize id in Response before result/error fields #1421

Merged
merged 1 commit into from
Jul 4, 2024

Conversation

ArtificialPB
Copy link
Contributor

Motivation

This change makes it possible to avoid buffering the result before being able to know how to decode it when using streaming response decoders.

For example, when using a WS connection, the client must track request ID's to know how to decode a response returned by the server. When using streaming-based JSON deserializers, you must buffer the result until you deserialize the ID of the response. This is wasteful for large / frequent messages.

Buffering example from a library we're developing: https://github.com/Kr1ptal/ethers-kt/blob/master/ethers-providers/src/main/kotlin/io/ethers/providers/WsClient.kt#L385-L394

Solution

Buffering can be avoided if the response serializes the ID before the result. The serialize function of Request type was updated to include the id field before result/error, see types/src/response.rs file changes. All other changes were made to update hardcoded test responses.

@ArtificialPB ArtificialPB requested a review from a team as a code owner July 4, 2024 15:19
@niklasad1
Copy link
Member

niklasad1 commented Jul 4, 2024

Do you have any hunch of much of perf benefit this is or data (benchmarks)? The fix is trivial so looks good to me

Copy link
Contributor

@lexnv lexnv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ArtificialPB
Copy link
Contributor Author

@niklasad1 based on a quick profiling run, buffering in ethers-kt takes about 50% of the decoding time, and increases the amount of generated garbage by around the same ratio.

Decoding is still fast with buffering, but it's much better without :)

Screenshot 2024-07-04 at 19 39 26

@niklasad1 niklasad1 merged commit 87999cf into paritytech:master Jul 4, 2024
10 checks passed
@ArtificialPB ArtificialPB deleted the feat/response-id-order branch July 4, 2024 19:39
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.

3 participants