Speeding Up Your First Request in Kentico by 50%
ASP.NET applications take their time when it comes to runtime compilation. And Kentico is no exception, as it is based on ASP.NET. Those who have been developing moderate-size or large applications know the story – after an application is compiled using msbuild in Visual Studio and the first page is requested, runtime compilation occurs. And the waiting comes. You have to wait for each page’s first load.
This is an unpleasant feature of ASP.NET and various efforts have been made to mitigate its impact. The best solution in terms of first load performance seems to be pre-compilation of the whole website. While this can be leveraged in a production environment, developers won’t like the time the pre-compilation requires after each change they make in the code. And sometimes there are other reasons why you want to avoid pre-compilation.
With all the changes.NET has brought recently (ASP.NET 5, .NET Core, VS2015), a new compiler platform came up – Roslyn. And luckily it has something to offer even for older .NET applications. About a month ago, the first production version of CodeDOM Providers for .NET Compiler Platform was released. It is distributed as a NuGet package and can be used in existing web site and web application projects. Provided that they target version 4.5 of the .NET framework.
If you are not familiar with NuGet package deployment in Visual Studio, see the project’s documentation.
Roslyn compilation offers 2 main pros for your projects. First, you can use new language features. And second, the runtime compilation time can decrease significantly, improving the application startup. Since this article is dedicated to performance, I will omit details on the language features and provide you with some findings regarding the latter benefit.
During our internal research and measurements, we wanted to form an opinion on what the compiler platform has to offer. And from the results, we can say that the performance boost is overwhelming. Our focus point was the first request time as mentioned above. We believe this is what bothers developers and end users a lot – developers do not like to be kept waiting when tuning the site and end users (i.e. your site visitors) feel the same way when shopping/reading news/doing other stuff.
Without getting into details, the increase in runtime compilation performance reduced the first request load time on our testing site (sample corporate site, web application project) by 50%.
While testing the NuGet package for web site projects, we ran into an issue when installing the package. Basically there seems to be a general problem when installing NuGet packages with \build imports into a web site project. If you want to try the compiler platform on web site projects despite the known issue, you have to modify the NuGet package manually and remove the \build folder from the package. However, this comes with no guarantee.
Regardless of whether you want to improve your site’s performance or like trying new things, you should reach out for the new CodeDOM Providers for .NET Compiler Platform. While it’s not always hassle free to get it going, the overall performance gain seems to be worth the effort.
Do you already have any experience with Roslyn and Kentico? Share it with us in the comments.