diff --git a/src/libraries/Common/src/Roslyn/SyntaxValueProvider_ForAttributeWithSimpleName.cs b/src/libraries/Common/src/Roslyn/SyntaxValueProvider_ForAttributeWithSimpleName.cs
index 3e6f947065a1d4..6ecbc1b35baaa7 100644
--- a/src/libraries/Common/src/Roslyn/SyntaxValueProvider_ForAttributeWithSimpleName.cs
+++ b/src/libraries/Common/src/Roslyn/SyntaxValueProvider_ForAttributeWithSimpleName.cs
@@ -334,7 +334,16 @@ void processMember(
// For any other node, just keep recursing deeper to see if we can find an attribute. Note: we cannot
// terminate the search anywhere as attributes may be found on things like local functions, and that
// means having to dive deep into statements and expressions.
- foreach (var child in node.ChildNodesAndTokens().Reverse())
+ var childNodesAndTokens = node.ChildNodesAndTokens();
+
+ // Avoid performance issue in ChildSyntaxList when iterating the child list in reverse
+ // (see https://github.com/dotnet/roslyn/issues/66475) by iterating forward first to
+ // ensure child nodes are realized.
+ foreach (var childNode in childNodesAndTokens)
+ {
+ }
+
+ foreach (var child in childNodesAndTokens.Reverse())
{
if (child.IsNode)
nodeStack.Append(child.AsNode()!);
diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/Microsoft.Extensions.Logging.Abstractions.csproj b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/Microsoft.Extensions.Logging.Abstractions.csproj
index e95fbc0ac99167..0539414bea2b4f 100644
--- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/Microsoft.Extensions.Logging.Abstractions.csproj
+++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/Microsoft.Extensions.Logging.Abstractions.csproj
@@ -6,6 +6,8 @@
true
true
true
+ true
+ 1
Logging abstractions for Microsoft.Extensions.Logging.
Commonly Used Types:
diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/LoggerMessageGeneratorParserTests.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/LoggerMessageGeneratorParserTests.cs
index 4bb4271e2655c9..e948d02f7269be 100644
--- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/LoggerMessageGeneratorParserTests.cs
+++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/LoggerMessageGeneratorParserTests.cs
@@ -767,6 +767,40 @@ partial class C
Assert.Equal(21, generatedSources[0].SourceText.Lines.Count);
}
+ [Fact]
+ public static void SyntaxListWithManyItems()
+ {
+ const int nItems = 200000;
+ var builder = new System.Text.StringBuilder();
+ builder.AppendLine(
+ """
+ using Microsoft.Extensions.Logging;
+ class Program
+ {
+ [LoggerMessage(EventId = 1, Level = LogLevel.Debug, Message = "M1")]
+ static partial void M1(ILogger logger)
+ {
+ """);
+ builder.AppendLine(" int[] values = new[] { ");
+ for (int i = 0; i < nItems; i++)
+ {
+ builder.Append("0, ");
+ }
+ builder.AppendLine("};");
+ builder.AppendLine("}");
+ builder.AppendLine("}");
+
+ string source = builder.ToString();
+ Compilation compilation = CompilationHelper.CreateCompilation(source);
+ LoggerMessageGenerator generator = new LoggerMessageGenerator();
+
+ (ImmutableArray diagnostics, _) =
+ RoslynTestUtils.RunGenerator(compilation, generator);
+
+ Assert.Single(diagnostics);
+ Assert.Equal(DiagnosticDescriptors.LoggingMethodHasBody.Id, diagnostics[0].Id);
+ }
+
private static async Task> RunGenerator(
string code,
bool wrap = true,
diff --git a/src/libraries/System.Text.Json/src/System.Text.Json.csproj b/src/libraries/System.Text.Json/src/System.Text.Json.csproj
index e572cda0d74274..dde9b4e507e7bf 100644
--- a/src/libraries/System.Text.Json/src/System.Text.Json.csproj
+++ b/src/libraries/System.Text.Json/src/System.Text.Json.csproj
@@ -8,8 +8,8 @@
CS8969
true
true
- false
- 2
+ true
+ 3
true
Provides high-performance and low-allocating types that serialize objects to JavaScript Object Notation (JSON) text and deserialize JSON text to objects, with UTF-8 support built-in. Also provides types to read and write JSON text encoded as UTF-8, and to create an in-memory document object model (DOM), that is read-only, for random access of the JSON elements within a structured view of the data.