views:

95

answers:

3

The VB.Net IDE allows me to scan for unused references. But I also have a lot of unused imports in my application. Is there a way to scan for unused imports in all classes, or does having an unused import not hurt the performance of my application?

+3  A: 

I believe this inclusion is done at compile time, and only on demand.

In other words, no performance penalty.

torkildr
+9  A: 

It doesn't hurt runtime performance at all, the only time those using directives are actually used is at compile time.

The three reasons why you could want to keep your import count low are :

  • For clarity sake. Imports are a usefull way to learn at first glance what kind of operations a class is performing : don't waste this opportunity ! (eg if I see a Regex namespace imported on top of a file, I usually assume there's some regex work in it)

  • The more imports you have, the more likely you are to run into a name clash (ie having one type name refering to two different types in two different imported namespaces)

  • Since those directives are used at compile time, having lots of unused import could hurt buildtime and/or intelliSense performance. (Just speculating here, I don't know how IntelliSense is working behind the scenes)

If you want to get rid of those useless namespaces, I don't think there's any built-in support for that in Visual studio (I assume this is what you meant by "the VB.net IDE"), but you can either use some third party tools (eg Resharper) or some other IDEs (eg Eclipse.net)

Brann
All I would add to this is that quality tools such as Resharper can tell you if they are used (exactly like looking up a code usage). The manual method is to delete one and see if it still builds!!!
Sohnee
A: 

First of all, unused / superfluous imports do not affect performance at all because of representing static, compile-time information only.

Second, tools like ReSharper exist to help you keep your code more maintainable, ease refactoring, clean-up obsolete stuff like unused imports etc.

Ondrej Tucny