Skip to content

Conversation

@Tinuvile
Copy link

@Tinuvile Tinuvile commented Oct 15, 2025

Why?

Currently fory rust deserialize API relies on compiler Return Value Optimization (RVO), which won't work always. And the compiler will copy small struct always.

What does this PR do?

fory.rs

add deserialize_into and deserialize_into_with_context method, the new API directly modifies the passed-in output parameter and returns () instead of the object itself, thus avoiding the copying of the return value.

serializers

in Serializer trait, add fory_read_into and fory_read_data_into, and it has been implemented for all types.

It seems this optimization will only be effective for primitive types and have limited effect on complex containers or dynamic types. I'm not sure if I'm on the right track right now, so I submitted this draft PR to seek some feedback.

Related issues

close #2552

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

@Tinuvile Tinuvile changed the title feat: support deserialize by populate passed mut ref feat(Rust): support deserialize by populate passed mut ref Oct 15, 2025
@chaokunyang
Copy link
Collaborator

Hi @Tinuvile , I refactored Serializer trait in #2774 , could you merge main branch and resolve the conflict?

@Tinuvile Tinuvile marked this pull request as ready for review October 16, 2025 06:58
@chaokunyang
Copy link
Collaborator

Hi @Tinuvile , does this PR improve performance for struct deserialization?

And for types which is not struct, maybe we don't need to support populate? We can limit the T to bound StructSerializer. In this way, only struct/enum can be passed in

@Tinuvile
Copy link
Author

Thanks for the feedback. I’ll check it again.

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.

[Rust] Support deserialize by populate passed mut ref

2 participants