-
Notifications
You must be signed in to change notification settings - Fork 218
Create a specialized pool for arrays of ClassifiedSpanInternal #11925
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
Create a specialized pool for arrays of ClassifiedSpanInternal #11925
Conversation
These arrays show up as a fairly large allocation in the typing scenario of the razor speedometer test. There are 150 MB (2.1%)of allocations of ClassifiedSpanInternal[] in the profile, but only 2.1 MB of ImmutableArray<ClassifiedSpanInternal>. This should be partly addressed by the earlier switch from DrainToImmutable use ToImmutableAndClear. However, this is also indicative that the 512 entry threshold for ArrayBuilderPool isn't sufficient for ClassifiedSpanInternal array counts. Roslyn has experienced this too and utilizes separate array pools for classification/tagging performance. The new pool has a threshold of 16K, much larger than the 512 entry limit. I tested this against a 60 KB razor file and was hitting about 7K entries, so this seemed like a pretty reasonable value.
| _spans.Add(span); | ||
| } | ||
|
|
||
| private class Policy : IPooledObjectPolicy<ImmutableArray<ClassifiedSpanInternal>.Builder> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: sealed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
One small note, if this visitor shows up in more traces, is that I've often thought its used, at least in modern tooling, in cases where there are simpler and probably faster alternatives, so it might be worth reviewing the specific stacks that cause it to show up. eg, its used to answer the question "what language is this?", but if the code only cares about if its C#, I suspect using our mapping service would be cheaper, since thats a binary search over already created data.
Agreed! Although, it's also worth noting that the data will be re-created on each keystroke. |
|
@dotnet/razor-compiler for 2nd compiler review |
Create a specialized pool for arrays of ClassifiedSpanInternal
These arrays show up as a fairly large allocation in the typing scenario of the razor speedometer test. There are 150 MB (2.1%)of allocations of ClassifiedSpanInternal[] in the profile, but only 2.1 MB of ImmutableArray. This should be partly addressed by the earlier switch from DrainToImmutable use ToImmutableAndClear. However, this is also indicative that the 512 entry threshold for ArrayBuilderPool isn't sufficient for ClassifiedSpanInternal array counts. Roslyn has experienced this too and utilizes separate array pools for classification/tagging performance. The new pool has a threshold of 16K, much larger than the 512 entry limit. I tested this against a 60 KB razor file and was hitting about 7K entries, so this seemed like a pretty reasonable value. To ensure this doesn't add to total memory usage, the pool is limited to only 5 entries, as cconcurrent execution of classification isn't common.
...