Are there any benefits to removing unused using statements in a VS project (such as can be done using Resharper), or will VS automatically take care of that when building/deploying?
4
There aren’t any performance benefits, if that’s what you mean.
All references in an assembly are fully qualified; the compiler merely uses the references you provide in your code to fully qualify identifiers, so the only impact of unused references in your source code is a slight decrease in readability (why is this reference here?), and a trivial increase in compile time.
To put it another way, the generated IL is exactly the same whether you remove the unused references or not.
4
Yes – I can think of two primary benefits:
- Beyond its primary functional purpose (i.e. to reduce code verbosity), the ‘Using’ statement list at the top of a code file can tell future readers (especially those without Resharper) which namespaces are (or at least were) relevant to that code file. If you actively prune this list, it can act as a better signaling mechanism.
- Removing unused namespaces will reduce the number of autocompletion candidates in your text editor as you type. If you rely on the autocompletion lists at all, this will help keep you “on the straight and narrow” and may even increase your typing speed, as you should be able to find your intended autocompletion candidate just a little bit faster.
1
It could possible happen that unused namespace left in your code will fail compilation after Nuget update if author of Nuget removed such namespace from new Nuget.
It is not much trouble, in such case, you just remove the namespace within nuget update.
1
Removing unused code, is just extra baggage and hard to measure the efficiencies gained.
-
Removing unused code, brings down the compilation time, I am working on a project which takes anywhere from 15 to 20 minutes, there is tons of unused code. Eliminating unused code decreased the compile time to ~7 minutes. This makes a diff when there are many developers on the team, this saves everyone time to quickly build and test.
-
If you have automated your build and unit tests, you have now removed unit tests you do not need. again this is reduced time taken to run unit tests. Just increased efficiency in your Continuous Build management process.
- Unused code results in bigger foot print of your binaries. Having a smaller code foot print will reduce the time taken to load/start up initially. Though the gains may be very meager and subjective.
4