Replace DotLiquid with Fluid#1346
Conversation
effc3f1 to
3bd34b2
Compare
|
Just out of curiousity, we made some changes to the parser in dotliquid. How does that benchmark for you? There are more improvements to be made but an idea of what needs to be done to keep DotLiquid would be good. Try compiling latest with this patch https://github.com/dotliquid/dotliquid/pulls/422 |
|
@microalps honestly I think it would serve DotLiquid best to have a benchmark suite in its own repository. I would think @sebastienros wouldn't mind if you use Fluid's comparison suite as starting point, you get a nice comparison report with it. |
|
@microalps have you looked at the benchmarks on the Fluid's page? It has DotLiquid ones. You can clone them and reference your fork to run them. But I doubt you would be able to "change" DL to the point it's comparable. At least for rendering it should be possible since it's less intrusive, no Regex should be necessary. |
|
Thanks for this PR - looks promising. |
Currently the "regressions" I see are some whitespace changes on NSwag side, like newlines and like removed whitespace for empty lines. These can be tweaked on NSwag side. I have already a branch that has template changes that fix most of the findings I have against TS/C# generation.
I'm committed to create a PR to integrate with NSwag and tweak until acceptable. Templates require mostly changes like from
Biggest change is the target frameworks, issue here: RicoSuter/NSwag#3384 . Easier maybe to do in iterations if we have open communication line to get things rolling. Here's the current diff for changes: https://github.com/RicoSuter/NSwag/compare/master...lahma:fluid?expand=1 |
2709a1b to
a89c347
Compare
|
I've rebased against master and updated the benchmarks (master with new Namotion.Reflection and this branch with new Namotion.Reflection). |
98dc811 to
07cf66d
Compare
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFrameworks>netstandard1.0;netstandard2.0;net40;net45</TargetFrameworks> | ||
| <TargetFrameworks>netstandard2.0;net461</TargetFrameworks> |
There was a problem hiding this comment.
This is a bit a problem as i know there are ppl using this lib with netstd < 2.0 and also with .NET 4.0
Is this really required?
There was a problem hiding this comment.
I restored the old targets, seems that we can keep this project targeting as-is. Good catch.
|
Converted to draft as I still need to one bigger round verifying the generated output (both our internal code base and NSwag outputs). |
So Fluid correctly handles this as specified by Shopify?
Please ping me when it's ready then ill have a look and we can continue integrating this (eg in NSwag). |
Yes, Fluid is very much stricter and follows the Shopify spec by the dot, correct me if I'm wrong @sebastienros .
I'll work with these, the latest changes in master just broke things a bit more, I'll probably submit a PR to fix regression and new performance issue. |
|
It follows Shopify as much as it can. And uses options to diverge. Same for filters, all based on specs, tests or manual testing on shopify.com directly. |
|
Seems that upgrading to latest Namotion.Reflection fixed the test problems, back to the original quest... |
|
Any updates on this PR? |
|
@RicoSuter I'm glad that you are still interested in this. I just returned from summer vacation so I'll try to sync this, it's a bit of a hurdle as I need to test both against the NJS and NSwag. But unfortunately there probably still be regressions due to Fluid being more standards compliant. |
|
@lahma good point, let's merge this ASAP... do you also have the work ready for the NSwag side so we can do this "quickly"? |
e0d60ee to
afc249a
Compare
* upgrade libs * reduce warnings to see the forest from the trees * optimize OrderByBaseDependency not to capture with lambdas and re-calculate indexes * optimize GetOrGenerateTypeName * use separate content loader to reduce re-loading from assemblies/disk * support child scopes when calling templates * write tabified version directly to writer * make template rewrite more deterministic, only add tab parameter if needed * improve tabCount logic * faster member segment traversal * ignore Subtypes_are_serialized_with_correct_discriminator on net461 * fix invalid Liquid, elseif should be elsif, invalid if conditions
|
@RicoSuter working on it, I'll ping back when I have verified that I get decent results out from the full toolchain |
|
PR looks good, thanks for that. |
|
@RicoSuter I think we are good to go, please be prepared that we might need couple iterations (hence beta), as this is quite complex beast. I have NSwag repo with required changes locally (local csproj references), let's see how it integrates with new package in real life... |
|
As this is quite the breaking change, I'd like to push NJS with a new major version and also add more breaking changes... |
|
I can create a draft PR which references packages from say, a lib folder as a temporary solution. |
|
I need to run some tests and try to reproduce, the template engine should be thread safe. |
|
I just run the csharp tests multiple times and sometimes it fails in the code output. |
|
I don't see how it is related to thread safety. Do I miss something or is the issue that a space is missing between |
yes, in this case, but i saw also other failures (rarely) where the output is missing other text... |
|
So IFluidTemplate.RenderAsync is thread-safe (if called in parallel)? |
|
That's the goal ... even for the same template. But your description of the issue feels familiar, I fixed a bug like this by the past, checking... |
|
Can you point me to the TextWriter and TextEncoder that is used? I remember it was a bug in a dotnet 5.0 hot fix (a breaking change) and I want to check if that could be this one. Unless you are not using 5.0. |
|
The template usage code is here. It uses default writers and encoders as it uses a strings output. |
|
@RicoSuter we are investigating and report back when we are wiser. |
|
@lahma can you repro this? Not sure where the problem is... must not be something with your change. |
|
Good news is that we can both repro locally by adding some concurrent runs, we should manage to isolate the problem. |
|
I believe I found the bug in Fluid. I suspected some code, read it, then understood how it could be an issue which happens to be exactly what we are seeing. Fixed the piece of code and now I can repro the bug. Will ship a new Fluid version in a few minutes. |
|
@RicoSuter OK so @sebastienros identified the problem, fixed it and now there's a new release (thank you!). I've opened #1426 with the new version, I can no longer get unit tests fail even running the parallel test we used in "Run until failure" mode. Thanks @RicoSuter for testing and reporting the problem! And I see it's already merged 😄 |
|
For those interested, NSwag migration to use Fluid is here: RicoSuter/NSwag#3679 |

TLDR; C# generation is now 15x faster and TS generation is 35x faster
There were some problems due to DotLiquid allowing invalid Liquid syntax (
elseifand some c# constructs) so some templates also needed to be changed. DotLiquid also didn't have correct whitespace handling for stripping trailing whitespace so that needed to be changed in templates. Target framework is now netstandard2.0/net461 which reflects what Microsoft officially supports.{%- %}instead of{% -%}elseifshould beelsif, some invalidifconditionsfixes #1345
Benchmarks