SQL CLR Slow at first start

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?
ismamicrosolutionsAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
DBAduck - Ben MillerConnect With a Mentor Principal ConsultantCommented:
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
 
DBAduck - Ben MillerPrincipal ConsultantCommented:
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
 
ismamicrosolutionsAuthor Commented:
But is there a way to bypass just in time or insert it as a more native language so no JIT need?
0
All Courses

From novice to tech pro — start learning today.