#I didn't realize that C# has an API to

1 messages · Page 1 of 1 (latest)

sly grail
#

The modularity of Dotnet is really something. ClientCompiler in CodeGenerator is one example of that, NuGetClient in Primer is another. Together they can reduce the runtime requirement from ~750 MiB to ~90 MiB. Which I think is still way larger than I'd like, but it's smaller than Node JS. The only ways I know of to make it substantially smaller is to delete core libraries that we don't think anyone would ever use, or set something up that fetches them on demand to a cache like with the NuGet dependencies. Both of those I think are too extreme.

Current implementation still uses the full SDK for the reference assemblies, but I have a change queued up for that.

amber prawn
#

I never use that feature before so I can't tell how much it reduces.

sly grail
#

Theoretically, yes, there should be. But I don't anticipate that a Dotnet Dagger module would ever reach the scale at which AOT is worthwhile.

The code constructing that we're talking about above is more about reducing cold start time. It's about "open process, read file, parse JSON, write syntax tree, compile tree, write dll file" vs "open process, read file, parse JSON, read template files, apply logic (with lots of hefty string reallocation), write file, close process, open compiler process (requiring large SDK), read files that were written, parse to syntax tree, compile tree, write dll file"

Also, there are nice things about generating via syntax tree beyond performance. It's easier to create abstractions. You can use LINQ to transform and filter, and it's much more readable (for me at least) than a template system where you're mixing partial C# fragments with golang fragments and dealing with string escaping.

params.Select(param => XmlParam(param.name, param.content))
vs

{% for param in params %}
<param name="{param.name}">{param.content}</param>
{% end %}

... which honestly isn't the best example, because that template code is actually pretty readable. I'll have to find a better one at some point.

amber prawn
#

That’s what I looking for. Currently , the SDK constructing code by using string concatination. It is easier than using template engine but it is still hard to read and cannot catch the syntax error, for example, the string interpolation https://github.com/dagger/dagger/blob/main/sdk/dotnet/sdk/Dagger.SDK.SourceGenerator/Code/CodeRenderer.cs#L331, or https://github.com/dagger/dagger/blob/main/sdk/dotnet/sdk/Dagger.SDK.SourceGenerator/Code/CodeRenderer.cs#L447.

This is why the syntax tree that you use in the SDK is looks really interesting to me. 🙂