-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Avoid compiling Razor views every time an application starts #2998
Description
Prerequisites
- I have written a descriptive issue title
- I have verified that I am running the latest version of Nancy
- I have verified if the problem exist in both
DEBUGandRELEASEmode - I have searched open and closed issues to ensure it has not already been reported (Permormance Issues using RazorViewEngine-Partial #2167 and very slow when perform the first request #2866 look similar but are not related)
Description
As mentioned in the thread #2866 compiling Razor views takes time. With the latest package from Nuget I found that launching the compiler for the first view takes 3-4 seconds and each additional view needs around 50 ms to compile.
This is an issue for a Nancy server in an application that users launch and expect to work with as quickly as possible. I understand that with the current Nancy architecture Razor views need to be compiled after each start of an application.
To ensure that a desktop application starts as quickly as possible I came up with a workaround that involves calling GetOrCompileView by reflection and a IViewCache implementation which writes the compiled assemblies to disk and loads them on subsequent starts. Rather hacky to say the least.
What I would like
- Get some feedback if there is a more straightforward way to avoid repeated view compilation
- If there is none, have better support in the Nancy framework for caching compiled Razor views
Steps to Reproduce
- Create project with
Nancy.Hosting.Self.NancyHostandRazorViewEnginewith a route returning a Razor view - Start application
- Open page in browser -> takes several seconds to respond
System Configuration
- Nancy version: 2.0.0 (Nuget)
- Nancy host
- Nancy.Hosting.Aspnet
- Nancy.Hosting.Self
- Nancy.Owin ()
- Other:
- Other Nancy packages and versions: Nancy.ViewEngines.Razor 2.0.0
- Environment (Operating system, version and so on): Windows 10
- .NET Framework version: 4.5.2