Skip to content

Conversation

@eiriktsarpalis
Copy link
Member

No description provided.

@eiriktsarpalis eiriktsarpalis self-assigned this Oct 19, 2022
@eiriktsarpalis eiriktsarpalis added this to the 8.0.0 milestone Oct 19, 2022
@ghost
Copy link

ghost commented Oct 19, 2022

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: eiriktsarpalis
Assignees: eiriktsarpalis
Labels:

area-System.Text.Json

Milestone: 8.0.0

{
int n;
if ((n = left.Count) != right.Count)
int leftCount = left is null ? 0 : left.Count;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious - when converters are not null - what's the chance that someone cached converter but didn't cache options? Won't this converters check realistically always be false?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly we could add equals and hash code to our implementations of converters and make them return trues when types match? That would make it relatively more likely to be true

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this converters check realistically always be false?

It would almost always be false, I wouldn't expect users to cache converters if they're not caching options.

Possibly we could add equals and hash code to our implementations of converters and make them return trues when types match? That would make it relatively more likely to be true

It might also be false because some converters accept parameters. We want to avoid false positives under all circumstances since it would lead to observable bugs -- on the other hand we tolerate false negatives since they can only result in reduced performance.

/// Once serialization or deserialization occurs, the list cannot be modified.
/// </remarks>
public IList<JsonConverter> Converters => _converters;
public IList<JsonConverter> Converters => _converters ??= new ConverterList(this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't thread-safe, in that two threads concurrently accessing this could end up getting different ConverterList instances. Is that ok?

And, it seems like this could transition from null to non-null even after being marked as isreadonly. Is that ok?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok for both cases, all logic consuming that field (including equality comparison in the global cache) has been updated so that null instances are equated to empty instances.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can, of course, result in issues when multiple threads attempt to configure the same mutable instance, but generally speaking the type is not designed to be thread safe while mutable.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants