Stop copied settings sharing mutations of the source serialization - #1895
Merged
Conversation
SerializationSettings is copy on write: the first serialization mutation on a
VerifySettings clones the global instance and sets isCloned, after which that
instance mutates its own copy in place.
The copy constructor assigned that same instance to the copy without clearing
isCloned on the source, so every later mutation of the source was applied in
place and observed by the copy:
settings.IgnoreMember("A");
var copy = new VerifySettings(settings);
settings.IgnoreMember("B"); // also ignored by copy
This also hit the eager copy the SettingsTask constructor takes, when the
original settings were mutated between two Verify calls.
The source is now marked as no longer the exclusive owner, so it clones before
its next mutation. Sharing until either side writes keeps the copy allocation
free, which matters since a copy is taken per verification.
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.
SerializationSettings is copy on write: the first serialization mutation on a VerifySettings clones the global instance and sets isCloned, after which that instance mutates its own copy in place.
The copy constructor assigned that same instance to the copy without clearing isCloned on the source, so every later mutation of the source was applied in place and observed by the copy:
This also hit the eager copy the SettingsTask constructor takes, when the original settings were mutated between two Verify calls.
The source is now marked as no longer the exclusive owner, so it clones before its next mutation. Sharing until either side writes keeps the copy allocation free, which matters since a copy is taken per verification.