Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove double array allocation in SemanticTokens #74271

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler.SemanticTokens
{
internal static class SemanticTokensHelpers
{
private static readonly ObjectPool<List<int>> s_tokenListPool = new ObjectPool<List<int>>(() => new List<int>(capacity: 1000));

internal static async Task<int[]> HandleRequestHelperAsync(
IGlobalOptionService globalOptions,
SemanticTokensRefreshQueue semanticTokensRefreshQueue,
Expand Down Expand Up @@ -243,7 +245,12 @@ private static int[] ComputeTokens(

var tokenTypeMap = SemanticTokensSchema.GetSchema(supportsVisualStudioExtensions).TokenTypeMap;

using var _ = ArrayBuilder<int>.GetInstance(5 * classifiedSpans.Count, out var data);
using var pooledData = s_tokenListPool.GetPooledObject();
var data = pooledData.Object;

// Items in the pool may not have been cleared
data.Clear();

for (var currentClassifiedSpanIndex = 0; currentClassifiedSpanIndex < classifiedSpans.Count; currentClassifiedSpanIndex++)
{
currentClassifiedSpanIndex = ComputeNextToken(
Expand Down
Loading