6

Developing a series of POCOs on my project, and just realized that some of them doesn't need the using System; clause.

Is there any performance or size penalty for leaving unused using <module>; on my objects or project ?

Will my classes get bigger, or slower, or bloated because of this or the compiler/optimizer is smart enough to take care of this?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Machado
  • 741
  • 2
  • 6
  • 19
  • 2
    that is one of the best practices , removing the unused namespaces – ashutosh raina Jan 11 '12 at 17:53
  • 3
    @ashutoshraina I don't know if I would call it a "best practice". It can increase readability, but has no effect on the code output. – Andrew Barber Jan 11 '12 at 17:55
  • @Platinum Azure, I could also compile my own kernel and write my customized version of Linux for my own purposes, but I don't. :-) – Machado Jan 11 '12 at 18:14
  • @Machado: Apples and oranges. I'm saying you shouldn't ask other people to do your work for you when you can totally measure everything yourself. – Platinum Azure Jan 11 '12 at 19:00
  • 1
    @PlatinumAzure, of course I could do that. I could go deeper and check the IL. That's not the point. Thanks to this question, I got some great answers about the using and how it affects the Intellisense, but not the output itself, plus I gained input from my fellow programmers about coding-style. If you don't like the question, please feel free to downvote it, it's your right. – Machado Jan 11 '12 at 22:48

8 Answers8

6

no there are not performance issue .

it is just a readability matter(I would suggest to remove them)

more info at: Why should you remove unnecessary C# using directives?

Community
  • 1
  • 1
Massimiliano Peluso
  • 26,379
  • 6
  • 61
  • 70
1

All the "using System;" statement does is allow you to use that namespace without fully qualified names. It doesn't affect run-time performance in any way.

itsme86
  • 19,266
  • 4
  • 41
  • 57
1

There is no runtime performance penalty for having unused using statements in your code. They don't appear is the compiled DLL in any form (they do exist in the PDB).

However if you know them to be invalid it's generally considered good style to remove them. Having unused usings is essentially stating a false dependency your code has on a set of types and extension methods.

Determining which usings are not used is a tedious process. I find it's best to just install a tool like PowerCommands and let it do the work on file save.

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
0

It has no impact on performance. It can be kept or removed at your discretion.

However, consider keeping it. The System namespace contains the most commonly used parts of the .NET Framework, and at some point during the lifetime of your file, you (or someone) will probably end up needing it. That means inevitably putting it back, possibly after wasting time wondering why none of the system classes exist.

Lily Finley
  • 2,847
  • 1
  • 16
  • 11
0

That brings neither performance gain nor hit.

I remove all unused and sort all used usings as code style (neatness). You can do this via Visual Studio context menu (I bound it to a hotkey).

abatishchev
  • 98,240
  • 88
  • 296
  • 433
0

If you are not using a reference / assembly or extended functionality for example using System.Linq; by default gets added to VS2010 projects.. if you don't use it.. just remove it.. no performance issues

MethodMan
  • 18,625
  • 6
  • 34
  • 52
0

The using directive is just syntactic sugar.

Adding using references will not affect performance other than a marginal compile-time difference.

McKay
  • 12,334
  • 7
  • 53
  • 76
0

It in no way affects the output of the compiler or the performance of the compiled program!

It can be removed a as part of personal preference. I would personally recommend it as it would make the compilation faster (fewer namespaces for the compiler to look up) and also improve the performance of intellisense.

Saurabh
  • 1,055
  • 14
  • 38