SchlenkR / Trulla

Type Safe Text Templates - usable as type provider (F#) or source generator (C#)
Apache License 2.0
61 stars 0 forks source link

Missing `for` causes dotnet run to hang #16

Open OnurGumus opened 2 months ago

OnurGumus commented 2 months ago

Hi I am basically trying to use Trulla for a large file. And build process becomes very slow for minutes. Any ideas? Update:

When I miss for keyword as in below., dotnet run hangs {{x in correlationTypes}}x{{end}}

When you add the for thing then it works fine {{for x in correlationTypes}}x{{end}}

OnurGumus commented 2 months ago

And I think the problem is with your parser, I tried both F# and C# stuff. They are both very slow.

SchlenkR commented 2 months ago

You have an example?

OnurGumus commented 2 months ago
<tr hx-include="this" hx-swap="outerHTML" hx-vals='{"{{phasesCombination.Key}}": "{{phasesCombination.Value}}"}'>
    <td><label>{{saturationNumber}}<input hidden name="SaturationNumber" value="{{saturationNumber}}"/></label></td>
    <td><label>{{property}}<input hidden name="Property" value="{{property}}"/></label></td>
    <td>
        <select
            class="select"
            name="Distribution"
            hx-put="{{uri}}"
            hx-target="closest tr"
            hx-include="closest tr">
            {{x in options}}x{{end}}
        </select>
    </td>
    <td>
        <input
            name="Mean"
            placeholder="Mean"
            type="number"
            value="{{mean}}"
            hx-put="{{uri}}"
            hx-target="closest tr"
            hx-include="closest tr"/>
    </td>
    <td>
        <input
            name="StandardDeviation"
            placeholder="Standard Deviation"
            type="number"
            value="{{standardDeviation}}"
            {{if isConstant}}disabled{{end}}
            hx-put="{{uri}}"
            hx-target="closest tr"
            hx-include="closest tr"/>
    </td>
    <td>
        <input
            name="LowerBound"
            placeholder="Lower Bound"
            type="number"
            value="{{lowerBound}}"
            {{if isConstant}}disabled{{end}}
            hx-put="{{uri}}"
            hx-target="closest tr"
            hx-include="closest tr"/>
    </td>
    <td>
        <input
            name="UpperBound"
            placeholder="Upper Bound"
            type="number"
            value="{{upperBound}}"
            {{if isConstant}}disabled{{end}}
            hx-put="{{uri}}"
            hx-target="closest tr"
            hx-include="closest tr"/>
    </td>
    <td>
        <select
            class="select"
            name="DependentProperty"
            {{if isConstant}}disabled{{end}}
            hx-put="{{uri}}"
            hx-target="closest tr"
            hx-include="closest tr">
            {{x in dependentProperties}}x{{end}}
        </select>
    </td>
    <td>
        <select
            class="select"
            name="CorrelationType"
            {{if isNoDependency}}disabled{{end}}
            hx-put="{{uri}}"
            hx-target="closest tr"
            hx-include="closest tr">
            {{x in correlationTypes}}x{{end}}
        </select>
    </td>
</tr>
OnurGumus commented 2 months ago

By slow what I mean is running dotnet run takes minutes from command line

OnurGumus commented 2 months ago

And here's some profiling stack trace

[Trulla.DesignTime] ProviderImplementation.ProvidedTypes.TypeProviderForNamespaces::Microsoft.FSha▒
+   52,25%     0,00%  [JIT] tid 90934              [.] instance class ProviderImplementation.ProvidedTypes.ProvidedTypeDefinition [Trulla.DesignTime] <StartupCode$Trulla-DesignTime>.$ProvidedTy▒
+   52,25%     0,00%  [JIT] tid 90934              [.] class ProviderImplementation.ProvidedTypes.ProvidedTypeDefinition [Trulla.DesignTime] Trulla.DesignTime.Internal.ProviderCompiler::createT▒
+   52,25%     0,00%  [JIT] tid 90934              [.] instance valuetype TheBlunt/ParserResult`1<class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<valuetype TheBlunt/PVal`1<class Tr▒
+   52,25%     0,00%  [JIT] tid 90934              [.] instance valuetype TheBlunt/ParserResult`1<class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<valuetype TheBlunt/PVal`1<class Tr▒
+   49,95%     0,22%  [JIT] tid 90934              [.] instance valuetype TheBlunt/ParserResult`1<class [netstandard]System.Tuple`2<class Trulla.Core.Token,string>> [Trulla.DesignTime] Trulla.C▒
+   43,37%     0,13%  [JIT] tid 90934              [.] instance valuetype TheBlunt/ParserResult`1<class Trulla.Core.Token> [Trulla.DesignTime] Trulla.Core.Parsing+Internal+templateExp@96-8::I
OnurGumus commented 2 months ago

@SchlenkR It seems I was able to narrow down the problem. Notice above code is missing the for keyword. {{x in correlationTypes}}x{{end}}

If you use like above then it gets stuck when you do dotnet run When you add the for thing then it works fine

{{for x in correlationTypes}}x{{end}}

While admit this is a bug on our case, the error handling can be improved. Will update the title.

SchlenkR commented 2 months ago

Oh, that's so nice, thanks for your work. I'll have a look at it soon! How urgent is the issue for you? Blocker in important work or so?

OnurGumus commented 2 months ago

Thanks, I guess so far, we don't have any problems as long as we adhere to the proper syntax.

Having that said, my concern is if this issue manifests itself in a different way in the future, then it might be bad :)