Introducing DotNet.SystemCollections.Analyzers

I have been a developer for the past 7 years. I’ve gone through a lot of code reviews during that time. I have devoted my time to learn good software engineering practices through C#. Last year, my passion for performance engineering took off.


One thing that has always been important for me was to be able to give back. The technical community is very open and was essential to bringing me where I am today. I wanted to be able to also help someone else. And an idea sparked into my mind last year. I wanted to find a way to help developers’ potential performance issues. Being notified at design-time would be beneficial for a software team.


With my colleague, I started working on this idea. Last January, we came up with a nice approach and worked on it in the first internal hackathon of Hypertherm Inc. The internal hackathon project was something I spearheaded in the company to help spark the creativity of developers.


By leveraging meta-programming and the Roslyn compiler, we were able to get a working solution. Meet your new analyzer library – .NET System.Collections Analyzers! The source code is available on GitHub under the MIT license.

Some examples of analysis

Analyzing using Last() on an IList
Analyzing using ElementAt on an IList
Analyzing using Distinct on IEnumerable
Analyzing using Contains on List

What are the goals of the library?

The purpose of this library is to empower the software developers using .NET. Leveraging best practices can make a difference from a quality or performance perspective. The library wants to pinpoint the issues about the usage of types found in System.Collections such as IEnumerable<T> or extension methods found in System.Linq. This tool is here to help developers make better performance decisions through a set of micro-optimizations.

Why another code analysis library?

There are many code analysis libraries for .NET, but they do not focus on how we should use data structures such as an List<T>. Frameworks are useful tools to help developers create a positive impact in their respective business. .NET is no exception to that rule. The problem is that even though you can use a list everywhere just because you’re used to its APIs doesn’t mean you should. Each collection serves a different purpose. Knowing what’s inside your toolbox and when would be the best time to use them makes a difference.

What analysis is currently available?

You will be able to find both performance and quality sensitive analyzers on the repository. You can read more in the documentation section of the project. As mentioned earlier, the project is still a PoC. We’ll continue to work on the tool in the future.

What’s on the roadmap in the near future?

Here are the most important directions of work:

  • Fix the issues with false-positives
  • Discuss within the team to decide which analyzers will be applied and which won’t be applied and why
  • Continue developing code analysis
  • Provide a suite of code fix providers so the library can help refactoring the code

Feedback is welcome!

This is an open source tool! The feedback is welcome and we encourage the community to come and submit PRs to the project.

Until next time,

Kevin

Published by

2 responses to “Introducing DotNet.SystemCollections.Analyzers”

  1. […] Introducing DotNet.SystemCollections.Analyzers – Kevin Avignon […]

    Liked by 1 person

Leave a comment