Skip to content

Commit

Permalink
Change from ArrayBuilder => SharedPools for pooling inside AddBracePa…
Browse files Browse the repository at this point in the history
…irsAsync (#75630)

It's pretty common for this array to exceed the size threshold supported by ArrayBuilder (128). For the files I'm testing on, the size supported by SharedPools (512) works much better.

Noticed this due to allocations in the editor's scrolling speedometer test, where it was showing up as 1.5% of allocations during scrolling.
  • Loading branch information
ToddGrun authored Oct 25, 2024
1 parent 99860e4 commit 937d1a4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Features/Core/Portable/BracePairs/IBracePairsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.LanguageService;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.BracePairs;
Expand Down Expand Up @@ -46,9 +47,11 @@ public async Task AddBracePairsAsync(
Document document, TextSpan span, ArrayBuilder<BracePairData> bracePairs, CancellationToken cancellationToken)
{
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
using var _ = ArrayBuilder<SyntaxNodeOrToken>.GetInstance(out var stack);

stack.Add(root);
using var pooledStack = SharedPools.Default<Stack<SyntaxNodeOrToken>>().GetPooledObject();
var stack = pooledStack.Object;

stack.Push(root);

while (stack.TryPop(out var current))
{
Expand Down

0 comments on commit 937d1a4

Please sign in to comment.