Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cost of using references to namespaces you don't need in C#

Tags:

performance

Is there any significant cost to using a reference to a namespace you don't need? I'm thinking the members probably live on the heap somewhere, tying up memory. The reason I ask is because I noticed some old references I no longer need in some production code and am wondering if it is worth refactoring in the short term.

like image 542
Marcus Santodonato Avatar asked Sep 12 '25 04:09

Marcus Santodonato


1 Answers

Not at all.

Namespaces and using statements are a purely compile-time construct.
At runtime, all references to classes and members refer to the actual member including the full namespace.
Extra using statements will have a minute impact on compile time, since the compiler will need to search more namespaces for each classname.

Unused assemblies also have no impact; assemblies aren't loaded until they're used.

like image 104
SLaks Avatar answered Sep 14 '25 20:09

SLaks