How does performance affect an unused directive?

Visual Studio will automatically create using statements for you whenever you create a new page or project. Some of them you will never use.

Visual Studio has the useful function "delete unused files."

I wonder if there is any negative impact on program performance if usage statements that are never available remain at the top of the file.

+66
c # visual-studio using
Jul 22. '09 at 2:31
source share
6 answers

Unused usage does not affect the performance of your application at runtime.

This can affect the performance of the IDE and the overall compilation phase. The reason is that it creates an additional namespace in which name resolution should be performed. However, they are usually negligible and should not have a noticeable effect on your IDE experience for most scenarios.

It can also affect the performance of evaluating expressions in the debugger for the same reasons.

+83
Jul 22 '09 at 2:34
source share

No, it's just a compilation / coding style style. .NET executables use full-featured names under the hood.

+11
Jul 22 '09 at 2:33
source share

It does not affect the execution speed, but there may be some effect on the compilation speed / intellisense, since there are more potential namespaces to find the appropriate class. I wouldn't worry too much about this, but you can use the Arrange Usage menu item to delete and sort using statements.

+5
Jul 22 '09 at 2:34
source share

Code that does not execute does not affect program performance.

+5
Jul 22 '09 at 2:46
source share

No, when compiling a program, several processes are executed. When the compiler starts looking for links (classes, methods), it will use only those that are used in the code. The using directive tells only the compiler where to look. Many unused statements may have performance issues, but only at compile time. At run time, all external code is correctly linked or included as part of the binary.

+4
Jul 22 '09 at 2:36
source share

Next link A good read on why removing unused links explains how useful it is to remove unused links from an application.

Below are some excerpts from the link:

  • By removing unused links in your application, you prevent the CLR from loading unused link modules at run time. This means that you will reduce the startup time of your application, as it takes time to load each module and avoids having compiler download metadata that will never be used. You may find that depending on the size of each library, the startup time is noticeably reduced. This does not mean that your application will be faster after downloading, but it can be quite convenient to know that your startup time can be reduced.

  • Another advantage of removing any unused links is that you reduce the risk of namespace conflicts. For example, if you have both System.Drawing and System.Web.UI.WebControls you will find that there are conflicts when trying to link to Image . If you use directives in your class that match these links, the compiler cannot determine which ones to use. If you regularly use autocomplete during development, deleting unused namespaces will reduce the number of autocomplete values ​​in your text editor as you type.

+1
May 11 '17 at
source share



All Articles