Click here to Skip to main content
13,295,192 members (64,100 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 22 May 2010

Static Constructor and Performance

Rate this:
Please Sign up or sign in to vote.
.Net Performance Tip - 1
.Net Performance Tip - 1

There are 2 modes by which the CLR emits the JIT code while executing static type constructor

1) Precise mode
2) Before - field - Init Mode

In Precise mode - the code will be Jitted just beofe the first initialization/access call to a static variable

In Before - field - Init Mode - it will be Jitted during the first instance creation of the type

Hence, Before field init mode is much more performant intent than the precise mode,as shown below

public class BeforInitMode
 static int i = 20;

In before init Mode - type constructor is jittted much before the static member variable initialization/access

public class PreciseMode
  static int i;
  static PreciseMode()
   i = 20;

In this mode - type constructor is jitted just beofre the first type variable initilization/access

Ref: CLR via C# by Jeffrey

I hope this helps!.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Vinayaka Krishna Shenoy
Architect MindTree Ltd
India India
Motivated achiever who guides organizations in applying technology to business settings, provides added value, and creates project deliverables in a timely manner. An experienced Technical Consultant, have successfully led large project teams of more than 20 people from requirements gathering to implementation and support using C#, .NET ,ADO.NET, ADO.NET Entity Framework,ASP.NET,ASP.NET MVC, WCF and SQL Server.

You may also be interested in...

Comments and Discussions

GeneralReason for my vote of 1 useless without numbers Pin
SledgeHammer0122-May-10 9:08
memberSledgeHammer0122-May-10 9:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 22 May 2010
Article Copyright 2010 by Vinayaka Krishna Shenoy
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid