Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do the amount of namespaces affect performance?

In Visual Studio there is a command to remove unused using statements

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

Is there a performance hit for having unused usings?

like image 205
O.O Avatar asked Dec 07 '10 16:12

O.O


1 Answers

The number of namespaces used in code files does not impact the runtime performance of the application. It does have an impact on compile time as the compiler must search those namespaces for additional items such as types and extension methods.

The only runtime impact the number of namespaces I'm aware of are

  • Debugging: The set of used namespaces in a given code file is stored in the PDB and consulted by the debugger during name resolution. Having a lot of namespaces could theoretically impact the performance of the debugger but in practice I haven't seen this be a problem.
  • Asp.Net: If using the deployment model where pages are compiled on first view by users, the number of namespaces can affect load time the first time a given page is viewed
like image 63
JaredPar Avatar answered Nov 04 '22 06:11

JaredPar