cavillac
cavillac

Reputation: 1311

Can redundant "using"s degrade performance

Just a performance question ...

Let's say I have 5 classes and each of them have a reference to System.Data and a homegrown Library. The 5 classes in question are a part of a Class Library and will eventually be built and published up to some web applications as a reference.

Is there any size/performance gained by taking the functions that reference System.Data and the other Library to their own class so that the number of times System.Data and my other Library gets referenced is reduced from 5 to 1? Common Sense is telling me that it doesn't matter because the DLLs would get read at the point of one of those functions being executed so it wouldn't matter where they sit or how many times you have "using System.Data" in your codebase ... but I've been wrong before :)

Upvotes: 6

Views: 196

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1503080

No - using directives don't add references to assemblies; they import namespaces for code in the same scope. All they're doing is allowing you to use

Foo foo = new Foo(); // etc

in your code instead of

Some.Namespace.Containing.Foo foo = new Some.Namespace.Containing.Foo();

They don't change which assemblies are being referenced at all. It's important to understand the different between namespaces and assemblies - unfortunately as they often use the same names, it can be confusing. As an example of where they're different, the Enumerable class in the System.Linq namespace is in the System.Core assembly.

Upvotes: 10

Related Questions