-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Generate an assembly and persist it to disk (Precompile views) #491
Comments
Can you discuss why this is better than creating a global tool to precompile the views, and load the precompiled views instead? |
Just wondering, if this might be an x-y problem - what does your PowerShell code look like that the performance is so abysmal? Can you quantify it? How many calls are you making, how long do the calls take, why do you think it is slow... any additional info probably helps discover what your performance issue really is. |
@jzabroski - Sure.
So the entire logic could be done in C#, but it raises the bar for those who need to maintain this code. I want to make Razor available in scripting. Now the timings. I am attaching two file - one before the change and the other is after the change. Now I recognize the Powershell code could be structured differently - it could prepare all the input up front and call the tool once, but that complicates the tool and make it less generic. Right now the tool has a very simple interface - "give me the template, give me the json and optionally give me a json query and I will render your template from the given json". The change I suggest would make it much faster in scripting and it does not seem to be costly or cause any regression, does it? (Please, ignore the name of the tool - |
No, it is not better. I am constrained in time and so need to improvise. That is the only reason. If I knew the amount of work needed to bring the global tool into the production state, then maybe I could contribute to it and accelerate its release. |
Don't you effectively have everything you need in your code snippet above? https://stackoverflow.com/a/73103966/1040437 It's just rather than making it a caching provider, you call the compiler directly and cache the generated assembly at the very end. |
I need to think about it. |
I am looking at it, but I have a question about the unit tests - some of them are failing at master. Am I correct? |
@MarkKharitonov Believe this is resolved now that I merged your PR. Thanks for this incredible contribution. Makes open source worth it and a reminder why I still do it. |
Excellent. Thank you very much. |
@jzabroski - I posted a PR that fixes the unit tests. Could you have a look? |
Looking |
Release created, it should flow up to nuget.org in about an hour. Release Notes: https://github.com/toddams/RazorLight/releases/tag/v2.2.0 Publish to Nuget action in progress (may fail if API key is out of date, in which case I may need Ivan's help): https://github.com/toddams/RazorLight/actions/runs/3253347419 |
Update - I forgot to update the pack publish pipeline to include the new project. I'm going to bump the version number and just hide the 2.2.0 release on nuget.org when I get a chance. |
Question - how does the precompile tool become available for usage? Ideally, it should be a dotnet tool, right? But I have not done anything special to enable it, not that I have ever done it before. |
I realized that now. You had IsPackable false. It should just be: <ToolCommandName>razorlight-precompile</ToolCommandName>
<PackAsTool>true</PackAsTool> |
I reached out to Ivan for help. The issue is our existing API key is tied to a finite list of packages rather than a generic glob pattern, so adding new packages won't work. |
Is there a usage example of this somewhere yet? Thanks! |
There are unit tests. For example, have a look at this precompile unit test - RazorLight/tests/RazorLight.Precompile.Tests/Render1Tests.cs Lines 97 to 116 in 2364883
|
@jzabroski - any update? |
2.3.0 has been up on nuget.org the last week. Sorry for not replying. nuget.org also reserved RazorLightTeam to have the RazorLight prefix going forward. Ideally you should have permission to be added to this team too if you'd like given the outsized size of your contrib. Up to Ivan tho. |
That is OK, I am fine with just being an outside contributor. Great news, thank you very much. |
Hi,
My use case - I am calling a small exe tool wrapping RazorLight from Powershell.
I have just a few templates, but a lot of model objects.
In order to keep the Powershell code well organized I end up calling the tool for the same templates multiple times. As a result the performance is abysmal.
However, if I could persist the generated assembly, then there would be a way to reuse it across the different calls.
Unfortunately, I failed to find how to do it.
What am I missing?
P.S.
I asked the same question on SO - https://stackoverflow.com/questions/73081390/is-there-an-off-the-shelf-implementation-of-the-razorlights-icachingprovider-th
The text was updated successfully, but these errors were encountered: