Refactor Moq1300 to use IOperation-based analysis instead of syntax analysis. This method results in a slightly less specific diagnostic (it uses the location of the entire .As<T>() method instead of only the type parameter, however it has several benefits:
About double the performance / speed
Cuts the memory allocations in half
I believe a bit more robust to "interesting" syntax trees
Here's a BenchmarkDotNet run comparing the old and new analyzers:
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Gen1 | Gen2 | Allocated | Alloc Ratio |
|-------------------------- |---------:|--------:|---------:|------:|--------:|----------:|----------:|----------:|----------:|------------:|
| OldMoq1300WithDiagnostics | 204.2 ms | 5.01 ms | 14.44 ms | 1.72 | 0.13 | 8000.0000 | 4000.0000 | 1000.0000 | 69.35 MB | 1.36 |
| NewMoq1300WithDiagnostics | 162.3 ms | 3.21 ms | 3.15 ms | 1.38 | 0.06 | 6000.0000 | 2000.0000 | - | 62.42 MB | 1.22 |
| Moq1300Baseline | 118.0 ms | 2.35 ms | 5.12 ms | 1.00 | 0.00 | 5000.0000 | 2000.0000 | - | 50.97 MB | 1.00 |
Refactor Moq1300 to use
IOperation
-based analysis instead of syntax analysis. This method results in a slightly less specific diagnostic (it uses the location of the entire.As<T>()
method instead of only the type parameter, however it has several benefits:Here's a BenchmarkDotNet run comparing the old and new analyzers: