Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 28, 2026

Replace heap allocations with pooled arrays in LoadMultipleUpdatesRows to reduce GC pressure in high-throughput scenarios.

Changes:

  • Rent ids and numbers arrays from ArrayPool<int>.Shared instead of allocating
  • Wrap method body in try-finally to ensure arrays are returned to pool
  • Update Array.Sort to use range overload: Array.Sort(ids, 0, count)
  • Create exact-sized arrays via AsSpan(0, count).ToArray() when passing to Npgsql (required by API)

Implementation:

var ids = ArrayPool<int>.Shared.Rent(count);
var numbers = ArrayPool<int>.Shared.Rent(count);

try
{
    // Use pooled arrays for all intermediate operations
    Array.Sort(ids, 0, count);
    
    // ... batch operations ...
    
    // Create properly-sized arrays only for Npgsql
    var idsArray = ids.AsSpan(0, count).ToArray();
    updateCmd.Parameters.Add(new NpgsqlParameter<int[]> { TypedValue = idsArray, ... });
}
finally
{
    ArrayPool<int>.Shared.Return(ids);
    ArrayPool<int>.Shared.Return(numbers);
}

Pooled arrays are reused for random number generation, sorting, and batch query building. Only the final parameter arrays require allocation due to Npgsql's API requirements.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: sebastienros <1165805+sebastienros@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 28, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 0t3vsblobprodcus362.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build -c Release (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-cache (dns block)
  • bcnvsblobprodcus378.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build -c Release (dns block)
  • h6tvsblobprodcus346.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build -c Release (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-cache (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build -c Release (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-cache (dns block)
  • m6xvsblobprodcus342.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build -c Release (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-cache (dns block)
  • m8dvsblobprodcus37.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build -c Release (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-cache (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] WIP address feedback on improving updates query for platform Use ArrayPool for int arrays in UPDATES query Jan 28, 2026
Copilot AI requested a review from sebastienros January 28, 2026 16:28
@sebastienros sebastienros deleted the copilot/sub-pr-2132 branch January 28, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants