Skip to content

refactor!: Optimize serialization and make it compatible with more data formats #437

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

Merged
merged 1 commit into from
Jun 28, 2024

Conversation

mwcampbell
Copy link
Contributor

My previous use of serde wasn't compatible with many data formats other than JSON, particularly those that serialize enum discriminants as integers rather than strings, and those that require the size of a map to be specified at the start of serialization.

To solve this, I've refactored the node structs internally. The dynamic properties are now stored in their own struct, and only that struct needs custom implementations of Serialize and Deserialize.

I also made serialization and deserialization more efficient by serializing the bitmasks for the actions and flags directly, rather than serializing the actions as a sequence and the flags as key/value pairs in the outer map.

The serialization to JSON, and similar formats, is now less human-friendly than it was. The dynamic properties are now stored in a sub-object inside the node object, and the actions and flags are now serialized as integers rather than something self-describing. But, in the real-world uses of serialization that are now important to us, like Newton, efficiency is more important than human readability. Newton will almost certainly switch from JSON to a binary format, like postcard or GVariant.

@DataTriny DataTriny changed the title refactor!: Make serialization more efficient and compatible with moreserde data formats refactor!: Optimize serialization and make it compatible with more data formats Jun 23, 2024
@DataTriny
Copy link
Member

The only downside I see with the JSON serialization being less human friendly is that I'd like UI toolkit developers to use serialized tree updates in non-regression testing at some point, akin to comparing screenshots to detect undesirable changes to styling. But that's only a minor inconvenience and I won't block on it. I'll finish reviewing this soon.

@DataTriny DataTriny merged commit 5a80d3a into main Jun 28, 2024
10 checks passed
@DataTriny DataTriny deleted the serde-refactor branch June 28, 2024 22:05
@mwcampbell mwcampbell mentioned this pull request Jun 27, 2024
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.

2 participants