-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
dotnet/roslyn-analyzers
#6850Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedapi-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Text.Jsonblocking-releasecode-analyzerMarks an issue that suggests a Roslyn analyzerMarks an issue that suggests a Roslyn analyzerin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is mergedtenet-performancePerformance related issuePerformance related issue
Milestone
Description
Forked from #40072.
While #64646 mitigates most of the performance issues related to creating single-use JsonSerializerOptions instances, this is still a suboptimal pattern and users are better off working with singleton JsonSerializerOptions instances. We should add an analyzer that warns about any JsonSerializerOptions construction that flows only to a call to a JsonSerializer method argument.
The analyzer should warn if any of the following patterns are detected:
JsonSerializer.Serialize(value, new JsonSerializerOptions { /* some custom config */ });or if we're passing a local that has been initialized in the same method
var options = useDefault ? JsonSerializerOptions.Default : new JsonSerializerOptions { /* some custom config */ };
foreach(object value in values)
{
JsonSerializer.Serialize(value, options);
}In both cases the analyzer should recommend lifting the options instance to a static variable or use DI, but would most likely not provide a fixer.
martincostello, N0D4N, krwq, ericstj, neon-sunset and 4 moreIEvangelist
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedapi-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Text.Jsonblocking-releasecode-analyzerMarks an issue that suggests a Roslyn analyzerMarks an issue that suggests a Roslyn analyzerin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is mergedtenet-performancePerformance related issuePerformance related issue