Hacker News new | ask | show | jobs
by delta_p_delta_x 897 days ago
It is pretty impressive that even without third-party tools, the binary went from 64 MB to ~1 MB. IMO future versions of .NET should add more of such optimisation flags as default in a Release build.
3 comments

You don't want these optimisations to be on by default.

Trimming can cause bugs when your program or one of its libraries relies on reflection and Native AOT is good for startup time (FaaS), but tiered JIT will likely outperform it in long-running applications.

> when your program or one of its libraries relies on reflection

Fair enough; perhaps it'd be worthwhile to throw a compiler error if both reflection and trimming were attempted.

> Native AOT is good for startup time (FaaS), but tiered JIT will likely outperform it in long-running applications

This is intriguing; could you elaborate on the latter? Would tiered JIT perhaps have more runtime information which would be more useful when optimising frequently-accessed code paths or tight loops?

> Fair enough; perhaps it'd be worthwhile to throw a compiler error if both reflection and trimming were attempted.

The tooling already generates warnings for any spot in the program that uses reflection _in a way that cannot be statically analyzed_. Fixing code to make it work with trimming is equivalent to fixing warnings. Here are a couple case studies: https://devblogs.microsoft.com/dotnet/creating-aot-compatibl...

> This is intriguing; could you elaborate on the latter? Would tiered JIT perhaps have more runtime information which would be more useful when optimising frequently-accessed code paths or tight loops?

Exactly. In addition to that, it's hard for the compiler to guess which branch is the frequent one in code. Or if it's the only one, if, for example, you link against implementations of some interface but only use one at runtime.

> Fair enough; perhaps it'd be worthwhile to throw a compiler error if both reflection and trimming were attempted.

In language/platform with dynamic loading, it's hard for the compiler to "perfectly" predict which piece of code will ending up being executed at compile time. I think would result in a lot of false positives.

No, but I learned from this that self-contained builds can be compressed. Why isn't that an option in the publish gui of vs 2022?
Agreed, it feels like there's still low-hanging fruit there.
It would be really interesting to see how small it could stay whilst adding in support for OpenGL.
Side note, one of the first commercial games written in .NET used OpenGL, released in 2004 long before XNA.

It was a RTS game and quite cool, Arena Wars.