Can rkyv do everything that Serde can do?

I'm considering whether to replace Serde with rkyv. Is rkyv able to do everything that Serde is able to do?

I'm especially thinking about these features:

  • Serde attributes (Attributes · Serde)
  • Serde custom Derive impl (i.e. passing the value that would have been in the field/variant into a trait method that changes things in customizable way before putting the resulting modification into the field/variant instead of the original value)

I don't think the two can be compared directly. You could compare serde with bincode to rkyv, but not just serde vs rkyv.

1 Like

so u mean rkyv is a superset of what Serde is able to do, and Serde needs to be combined with Bincode to have all the capabilities of rkyv?

No, rather serde (as an ecosystem) is basically a superset of what rkyv does, with bincode being the serde's subset more similar to rkyv. However rkyv is more specialized to what it does, and thus can do it faster.

So in the end serde provides you lot of flexibility but can be a little slower, while rkyv is much more limiting in what you can do but can do that very efficiently. As always, it's a matter of tradeoffs.

2 Likes

No, serde is an adapter, by itself it doesn't de/serialize, it defines an architecture de/serializers can re-use. serde separates the concerns of serialization/deserialization logic and the actual data format.

rkyv on the other hand is both the de/serializer and the format.

5 Likes

oh! ok how about comparing serde_json with rkyv. Can rkyv do everything that serde_json can do? I think serde_json is the actual de/serializer that uses the serde architecture, together with the format.

SkiFire already answered that. serde/bincode is what you'd compare to rkyv.

I have never used rkyv but I believe it's simply not as flexible as serde/bincode because of different goals. rkyv aims for performant deserialization. serde doesn't necessarily aim for performance, though it does achieve it.

The main question is: does your application domain need what rkyv offers? Specialized performance and zerocopy deserialization at the cost of a specialized data format (that no else can read back).

Keep in mind that you can use both serde and rkyv in different parts of your application.

6 Likes

I'm currently relying heavily on advanced features in serde-json but I'm considering if replacing some of that with rkyv may be beneficial. But you said rkyv is more comparable to serde/bincode rather than serde/json so perhaps rkyv isn't a viable replacement for serde_json

To me it would seem obvious you can't blindly swap JSON with rkyv. The two aren't used in the same contexts. JSON is used to communicate between machines, generally over HTTP APIs, sometimes for human readable configuration files, rkyv would be used for game dev asset loading, state serializing, maybe database servers.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.