perf(json-rpc): skip re-parse when returning owned Box<RawValue> - #4057
Merged
Merged
Conversation
The raw-request response path deserialized an already-owned Box<RawValue> back into Box<RawValue>, repeating a byte copy and a full JSON validation scan over a value that was already validated. When the requested response type is Box<RawValue>, hand the owned payload back directly via a TypeId guard, matching the existing transmute-based specialization in the boxed transport. This removes one copy and one validation scan per raw request.
mfw78
requested review from
DaniPopes,
grandizzy,
klkvr,
mattsse and
onbjerg
as code owners
July 3, 2026 06:09
mattsse
approved these changes
Jul 3, 2026
mattsse
left a comment
Member
There was a problem hiding this comment.
this seems okay, we only use it for raw_request_dyn and there we already enforce 'static owned I believe so the additional 'static is okay here.
wdyt @DaniPopes
Contributor
Author
|
The failing |
DaniPopes
approved these changes
Jul 3, 2026
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.
try_deserialize_okcallsserde_json::from_str::<Box<RawValue>>even whenJis alreadyBox<RawValue>, so the raw passthrough path (Provider::raw_request,RpcClient::request/batch withBox<RawValue>) copies and re-validates a payload it already owns on every response.When
JandTare bothBox<RawValue>, return the owned payload directly behind aTypeIdguard, matching thetransmute_copyspecialization inIntoBoxTransport::into_box_transport. The generic deserialize path is unchanged.This adds a
'staticbound to the (public)try_deserialize_ok, needed forTypeId. Both in-tree callers passBox<RawValue>; only external callers passing a borrowedJwould be affected.