perf: optimise SyntaxNodeComparer by TimothyMakkison · Pull Request #1730 · belav/csharpier (original) (raw)
belav added a commit that referenced this pull request
It appears that SyntaxNodeComparer is run after a file is formated,
optimisation here may be impactful
- Prevent null
Func<T, T, Result>allocations (still seeing some in the profiler, no idea how to sotp this) - Prevent boxing of
SyntaxTokenList,SyntaxNodeOrTokenList - Use
OrderBy.ToArrayinstead ofOrderBy.ToList - Create
AllSeparatorsButLastto prevent boxingSeparatedSyntaxList<SyntaxNode>andIEnumerablecreation
I have some other idea, but I'm focusing on the unhappy path right now.
Benchmark (comparing complexCode)
Before
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated | |--------------------------- |---------:|--------:|--------:|----------:|----------:|----------:|----------:| | Default_SyntaxNodeComparer | 229.1 ms | 4.55 ms | 7.60 ms | 5000.0000 | 3000.0000 | 1000.0000 | 40.53 MB |
After
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated | |--------------------------- |---------:|--------:|--------:|----------:|----------:|----------:| | Default_SyntaxNodeComparer | 187.4 ms | 3.51 ms | 7.64 ms | 3000.0000 | 1000.0000 | 31.39 MB |
Co-authored-by: Bela VanderVoort twobitbela@gmail.com
belav added a commit that referenced this pull request
It appears that SyntaxNodeComparer is run after a file is formated,
optimisation here may be impactful
- Prevent null
Func<T, T, Result>allocations (still seeing some in the profiler, no idea how to sotp this) - Prevent boxing of
SyntaxTokenList,SyntaxNodeOrTokenList - Use
OrderBy.ToArrayinstead ofOrderBy.ToList - Create
AllSeparatorsButLastto prevent boxingSeparatedSyntaxList<SyntaxNode>andIEnumerablecreation
I have some other idea, but I'm focusing on the unhappy path right now.
Benchmark (comparing complexCode)
Before
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated | |--------------------------- |---------:|--------:|--------:|----------:|----------:|----------:|----------:| | Default_SyntaxNodeComparer | 229.1 ms | 4.55 ms | 7.60 ms | 5000.0000 | 3000.0000 | 1000.0000 | 40.53 MB |
After
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated | |--------------------------- |---------:|--------:|--------:|----------:|----------:|----------:| | Default_SyntaxNodeComparer | 187.4 ms | 3.51 ms | 7.64 ms | 3000.0000 | 1000.0000 | 31.39 MB |
Co-authored-by: Bela VanderVoort twobitbela@gmail.com
belav added a commit that referenced this pull request
It appears that SyntaxNodeComparer is run after a file is formated,
optimisation here may be impactful
- Prevent null
Func<T, T, Result>allocations (still seeing some in the profiler, no idea how to sotp this) - Prevent boxing of
SyntaxTokenList,SyntaxNodeOrTokenList - Use
OrderBy.ToArrayinstead ofOrderBy.ToList - Create
AllSeparatorsButLastto prevent boxingSeparatedSyntaxList<SyntaxNode>andIEnumerablecreation
I have some other idea, but I'm focusing on the unhappy path right now.
Benchmark (comparing complexCode)
Before
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated | |--------------------------- |---------:|--------:|--------:|----------:|----------:|----------:|----------:| | Default_SyntaxNodeComparer | 229.1 ms | 4.55 ms | 7.60 ms | 5000.0000 | 3000.0000 | 1000.0000 | 40.53 MB |
After
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated | |--------------------------- |---------:|--------:|--------:|----------:|----------:|----------:| | Default_SyntaxNodeComparer | 187.4 ms | 3.51 ms | 7.64 ms | 3000.0000 | 1000.0000 | 31.39 MB |
Co-authored-by: Bela VanderVoort twobitbela@gmail.com
belav added a commit that referenced this pull request
It appears that SyntaxNodeComparer is run after a file is formated,
optimisation here may be impactful
- Prevent null
Func<T, T, Result>allocations (still seeing some in the profiler, no idea how to sotp this) - Prevent boxing of
SyntaxTokenList,SyntaxNodeOrTokenList - Use
OrderBy.ToArrayinstead ofOrderBy.ToList - Create
AllSeparatorsButLastto prevent boxingSeparatedSyntaxList<SyntaxNode>andIEnumerablecreation
I have some other idea, but I'm focusing on the unhappy path right now.
Benchmark (comparing complexCode)
Before
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated | |--------------------------- |---------:|--------:|--------:|----------:|----------:|----------:|----------:| | Default_SyntaxNodeComparer | 229.1 ms | 4.55 ms | 7.60 ms | 5000.0000 | 3000.0000 | 1000.0000 | 40.53 MB |
After
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated | |--------------------------- |---------:|--------:|--------:|----------:|----------:|----------:| | Default_SyntaxNodeComparer | 187.4 ms | 3.51 ms | 7.64 ms | 3000.0000 | 1000.0000 | 31.39 MB |
Co-authored-by: Bela VanderVoort twobitbela@gmail.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})