Solved

SQL CLR Slow at first start

Posted on 2010-09-02
3
915 Views
Last Modified: 2012-05-10
When I execute and SQL CLR store procedure, the first time .... it is really slow and then faster the second time. Is there a way to maintain this fast without having to trigger the storeprocedure every 1 minute?
0
Comment
Question by:ismamicrosolutions
  • 2
3 Comments
 
LVL 24

Expert Comment

by:DBAduck - Ben Miller
ID: 33593447
The reason is because the CLR is Common Language Runtime and is hosted by SQL Server.  It still follows the model of CLR applications in that it is compiled down to IL (Intermediate Language) and in order to execute must use a process called JIT (Just in Time) compiling to get to bytecode or executable code.  This is done once at the beginning of the first execution and from then on uses the bytecode produced.  

So in any CLR or .NET language, you will incur the cost of the JIT on the first invocation.  This is what you are seeing.

Also note that this only happens when the AppDomain is recycled, which is governed by the CLR and I am not sure how often that happens in SQL.
0
 

Author Comment

by:ismamicrosolutions
ID: 33593467
But is there a way to bypass just in time or insert it as a more native language so no JIT need?
0
 
LVL 24

Accepted Solution

by:
DBAduck - Ben Miller earned 500 total points
ID: 33593478
Not that I am aware of.  You will load the assembly with CREATE ASSEMBLY and in the validation it checks the MSIL.

So I am not aware of a way to create an assembly that has been NGEN'd to bytecode.  It will always JIT.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now