Repository navigation
Sort the keys of Mirror wire JSON so a repeated message has the same bytes - #1182
Merged
Merged
Conversation
…bytes JSONEncoder takes its key order from a dictionary, and that order can change between two calls for the same value. A repeated pane list then had different bytes, so the compressed stream could not refer back to all of it. The size of a repeat changed from run to run, and `aStreamRoundTripsEveryPayloadTypeAndShrinksRepeats` failed in CI when a repeat came to 64 bytes.
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.
Problem
MirrorWireCompressionTests/aStreamRoundTripsEveryPayloadTypeAndShrinksRepeats()fails in CI from time to time. The last failure was run 45992640420, with the sizes[349, 54, 64, 52, 18]against the limit< 64.MirrorWire.payloadused aJSONEncoderwithout sorted keys. The encoder takes its key order from a dictionary, and that order can change between two calls for the same value in one process. A small program that encoded one value 2000 times, with other allocations between the calls, got 4 different outputs.When the key order changes, a repeated pane list does not have the same bytes as the one before it. The compressed stream can then refer back to only a part of it, and the repeat is a few bytes larger.
This is not only a test problem: the Mac host compresses the messages that it sends, so the size of a repeated list on the wire also changed from one send to the next.
Change
The wire encoder sorts its keys. The clients parse the JSON and do not depend on the key order. The iOS and Android clients do not compress the messages that they send, so they are not changed.
Verification
aJSONPayloadHasOneKeyOrderfailed before the change and passes after it.make test(5180 tests),make check,make build-app