Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5961845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:01:23+00:00 2026-05-22T19:01:23+00:00

Does System.Activator.CreateInstance(T) method have performance issues (since I’m suspecting it uses reflection) big enough

  • 0

Does System.Activator.CreateInstance(T) method have performance issues (since I’m suspecting it uses reflection) big enough to discourage us from using it casually?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:01:24+00:00Added an answer on May 22, 2026 at 7:01 pm

    As always, the only correct way to answer a question about performance is to actually measure the code.

    Here’s a sample LINQPad program that tests:

    • Activator.CreateInstance
    • new T()
    • calling a delegate that calls new T()

    As always, take the performance program with a grain of salt, there might be bugs here that skews the results.

    The output (timing values are in milliseconds):

    Test1 - Activator.CreateInstance<T>() 
    12342 
    
    Test2 - new T() 
    1119 
    
    Test3 - Delegate 
    1530 
    
    Baseline 
    578 
    

    Note that the above timings are for 100.000.000 (100 million) constructions of the object. The overhead might not be a real problem for your program.

    Cautionary conclusion would be that Activator.CreateInstance<T> is taking roughly 11 times as much time to do the same job as a new T() does, and a delegate takes roughly 1.5 times as much. Note that the constructor here does nothing, so I only tried to measure the overhead of the different methods.

    Edit: I added a baseline call that does not construct the object, but does the rest of the things, and timed that as well. With that as a baseline, it looks like a delegate takes 75% more time than a simple new(), and the Activator.CreateInstance takes around 1100% more.

    However, this is micro-optimization. If you really need to do this, and eek out the last ounce of performance of some time-critical code, I would either hand-code a delegate to use instead, or if that is not possible, ie. you need to provide the type at runtime, I would use Reflection.Emit to produce that delegate dynamically.

    In any case, and here is my real answer:

    If you have a performance problem, first measure to see where your bottleneck is. Yes, the above timings might indicate that Activator.CreateInstance has more overhead than a dynamically built delegate, but there might be much bigger fish to fry in your codebase before you get (or even have to get) to this level of optimization.

    And just to make sure I actually answer your concrete question: No, I would not discourage use of Activator.CreateInstance. You should be aware that it uses reflection so that you know that if this tops your profiling lists of bottlenecks, then you might be able to do something about it, but the fact that it uses reflection does not mean it is the bottleneck.

    The program:

    void Main()
    {
        const int IterationCount = 100000000;
    
        // warmup
        Test1();
        Test2();
        Test3();
        Test4();
    
        // profile Activator.CreateInstance<T>()
        Stopwatch sw = Stopwatch.StartNew();
        for (int index = 0; index < IterationCount; index++)
            Test1();
        sw.Stop();
        sw.ElapsedMilliseconds.Dump("Test1 - Activator.CreateInstance<T>()");
    
        // profile new T()
        sw.Restart();
        for (int index = 0; index < IterationCount; index++)
            Test2();
        sw.Stop();
        sw.ElapsedMilliseconds.Dump("Test2 - new T()");
    
        // profile Delegate
        sw.Restart();
        for (int index = 0; index < IterationCount; index++)
            Test3();
        sw.Stop();
        sw.ElapsedMilliseconds.Dump("Test3 - Delegate");
    
        // profile Baseline
        sw.Restart();
        for (int index = 0; index < IterationCount; index++)
            Test4();
        sw.Stop();
        sw.ElapsedMilliseconds.Dump("Baseline");
    }
    
    public void Test1()
    {
        var obj = Activator.CreateInstance<TestClass>();
        GC.KeepAlive(obj);
    }
    
    public void Test2()
    {
        var obj = new TestClass();
        GC.KeepAlive(obj);
    }
    
    static Func<TestClass> Create = delegate
    {
        return new TestClass();
    };
    
    public void Test3()
    {
        var obj = Create();
        GC.KeepAlive(obj);
    }
    
    TestClass x = new TestClass();
    public void Test4()
    {
        GC.KeepAlive(x);
    }
    
    public class TestClass
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have any strategies/tips/traps for moving to Team System? Should it be done
Does system.Reflection work when I use release folder ?
How does operating system know what filesystem a partition is using? In other words,
Why does a System.Boolean take 4 bytes? It just stores one state, either true
I understand what System.WeakReference does, but what I can't seem to grasp is a
typeof(int).Name Will return System.Int32 does anyone know of a way to return int
Does anyone know of an application or system out there for tracking changes (files
Does anyone know of any 'standard' way to interface with a telephony system (think
Does anyone know of a better GUI client for displaying Windows System Monitor log
Exception Thrown: System.ComponentModel.ReflectPropertyDescriptor is not marked as Serializable Does this mean I missed marking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.