-
Notifications
You must be signed in to change notification settings - Fork 87
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
Remove JSON string escaping in diff messages #598
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I love how you went well over everything for this PR. Updated API reference, updated method and even added a release description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great stuff, real improvement I think!
Description of change
Removes JSON string escaping in
DiffMessage::diff
andServiceEndpoint
diffs. This reduces the size ofDiffMessages
on the Tangle by ~6%. This reduction has diminishing returns for larger diff messages, going to ~1% for 2KB and <1% for 3KB+, but considering we expect most diffs to be <1KB this would still have an impact.WARNING: this is a breaking change and will invalidate all prior diff chain updates. Advise developers using
0.5.0-dev.1
/0.5.0-dev.2
to publish an integration update with all diffs applied to prevent unexpected changes.Advantages
Disadvantages
IotaDiffDocument
up-front for everyDiffMessage
processed when resolving a DID (rather than only after the signature is validated). This could slow down resolution when there are many conflicting or spam messages on the diff chain but the effect is capped since Tangle message sizes have a reasonable upper-limit. Benchmarking (see section below after the example) shows this effect is significant but only in malicious cases since deserialization is always performed anyway for validDiffMessages
. Would not be an issue with planned spam solutions.Example:
A medium-sized
DiffMessage
which adds a service and a verification method.diff
(formatted for display).IotaDiffDocument
for the diff (formatted for display).Benchmarking Decompression+Deserialization
Benchmarking decompressing then deserializing a
DiffMessage
encoded as JSON with Brotli compression with criterion demonstrates the significant overhead of JSON deserialization (unescaped - this PR) compared to deserialising a string field (escaped - current). For context, the data was generated by adding [1, 10, 100, 1000, 10_000, 50_000] services to a DID Document.Note that this is not a performance regression since the difference demonstrated is simply the overhead of immediate JSON deserialisation. The orange line (escaped - current) simply defers the JSON deserialization of the diff field to the merge step.
This is only a problem if we have to deserialize many large diff messages on an index (from malicious actors for example), which should hopefully be solved by other spam prevention changes. Spamming large integration chain messages would have the same effect currently.
Type of change
How the change has been tested
Local tests and examples pass in both Rust and Wasm.
Change checklist