Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Core/Resolvers/QueryExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,17 @@ public async Task<JsonArray> GetJsonArrayAsync(
{
if (dbResultSetRow.Columns.Count > 0)
{
JsonElement result =
JsonSerializer.Deserialize<JsonElement>(JsonSerializer.Serialize(dbResultSetRow.Columns));
// Use a memory stream to serialize the columns
using MemoryStream ms = new();
using (Utf8JsonWriter writer = new(ms))
{
JsonSerializer.Serialize(writer, dbResultSetRow.Columns);
}

ms.Position = 0;
using JsonDocument doc = JsonDocument.Parse(ms);
Comment on lines +593 to +600
Copy link
Preview

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

This approach may not resolve the original OOM issue and could introduce performance overhead. The MemoryStream still allocates memory internally, and you're now creating additional objects (MemoryStream, Utf8JsonWriter, JsonDocument). Consider using JsonSerializer.SerializeToUtf8Bytes() and JsonSerializer.Deserialize() with ReadOnlySpan for better memory efficiency.

Suggested change
using MemoryStream ms = new();
using (Utf8JsonWriter writer = new(ms))
{
JsonSerializer.Serialize(writer, dbResultSetRow.Columns);
}
ms.Position = 0;
using JsonDocument doc = JsonDocument.Parse(ms);
byte[] jsonBytes = JsonSerializer.SerializeToUtf8Bytes(dbResultSetRow.Columns);
using JsonDocument doc = JsonDocument.Parse(jsonBytes);

Copilot uses AI. Check for mistakes.

JsonElement result = doc.RootElement.Clone();

// FromJsonElement() added to address .NET8 regression where the .Add() throws:
// System.InvalidOperationException: "The element cannot be an object or array."
resultArray.Add(FromJsonElement(result));
Expand Down