Reduce pooled array allocations in the SyntaxParser #76610
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These pooled array allocations are showing up in the roslyn editing speedometer test as 2.9% of allocations in the code analysis process.
The SyntaxParser has pools for holding the BlendedNode and SyntaxToken arrays it uses. However, it sets the size of the pool to be only 2 items. As these arrays are only released once the parser is disposed, and there are potentially quite a few concurrent parses going on during solution load, there ends up being quite a few allocations of these arrays due to earlier allocations not yet being released to the pool.
Instead, just switch these object pools to use the default for the array size.
Local testing for opening the Roslyn sln showed about 50K SyntaxParser objects constructed, and I was seeing the blended/token arrays allocated 3.5K/10.5K respectively. With this change, I saw those array allocations reduced to 18/54 respectively. Speedometer results look good (images below)
Without change speedometer allocations:
![image](https://private-user-images.githubusercontent.com/6785178/400008320-4fe77175-e6db-4a34-9eeb-10b07fa5f304.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0MjQwNTgsIm5iZiI6MTczOTQyMzc1OCwicGF0aCI6Ii82Nzg1MTc4LzQwMDAwODMyMC00ZmU3NzE3NS1lNmRiLTRhMzQtOWVlYi0xMGIwN2ZhNWYzMDQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTNUMDUxNTU4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MDFkYjBiMTJkYWMwODMxMGUyZGM3MWQzZjVkMGRlYzA1M2IyOGU0ZDFlM2FlZGQwYTZlZWYyNGQ2MzU5MDZmOSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.7kIRRCDv_Dguz5Im935BaW-aAv1FEjPrFtAsKSdshrg)
With change speedometer allocations:
![image](https://private-user-images.githubusercontent.com/6785178/400149969-44e7c1e6-72cf-46c8-8bcf-aa1e4c108301.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0MjQwNTgsIm5iZiI6MTczOTQyMzc1OCwicGF0aCI6Ii82Nzg1MTc4LzQwMDE0OTk2OS00NGU3YzFlNi03MmNmLTQ2YzgtOGJjZi1hYTFlNGMxMDgzMDEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTNUMDUxNTU4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MTA4N2M0OWZmYjEyMDUyMmJmZjYxZmUwYTc5ZTNkNTBhNzE2NzdkYWNhM2ZkYjNhNGU5YWI2ZTM4ZWE5OWNiZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.EByVuP3GRByzHZQp_kTR7nCXBn_k9sS07YMJ1dP2UEQ)