This is really cool, but it's funny to use C# primarily as an awkward substitute for C as you call Win32. For most practical purposes, the default .NET 8 AOT is great if you really need native code.
Windows Forms is basically this, a better MFC version, and even if it was only for faster startup times, NGEN has been there since day 1. The biggest issue has been WinDev, that contrary to Google's culture in ChromeOS and Android, they will kill any attempt to touch their precious COM and C++ tools, thus the way the Longhorn project went down, only to see its ideas redone in COM, and WinRT coming to existence.
Building a self-contained game in C# under 2 kilobytes
21–30 of 42 posts
Re: Building a self-contained game in C# under 2 kilobytes
#22Earlier quoted context omitted.
Windows Forms is basically this, a better MFC version, and even if it was only for faster startup times, NGEN has been there since day 1. The biggest issue has been WinDev, that contrary to Google's culture in ChromeOS and Android, they will kill any attempt to touch their precious COM and C++ tools, thus the way the Longhorn project went down, only to see its ideas redone in COM, and WinRT coming to existence.
WinRT is one of the biggest fail of Microsoft in the last decades. Instead of pushing for a multiplatform .NET implementation with a portable UI (Silverlight OOB was just that), or even running on most Windows versions, we got framework over framework (WinRT, UWP, WinUI) that are only compatible with the last version of Windows and don't bring value over WPF.
From the forced rewrites across Windows 8, 8.1 and 10, as the platform was maturing, the deprecation of C++/CX, replaced by less capable C++/WinRT (now in maintainance, while they are having fun in Rust/WinRT), deprecation of .NET Native without parity in Native AOT, no designer, and plenty of other broken stuff.
It was for this that WinDev kind of sabotaged Longhorn efforts, thanks very much.
Meanwhile Google shows what happens when everyone pushes into the same direction, even if it takes some growing pains (with lots of cash) to get there.
Re: Building a self-contained game in C# under 2 kilobytes
#23Re: Building a self-contained game in C# under 2 kilobytes
#24It 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.
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.
Re: Building a self-contained game in C# under 2 kilobytes
#25It 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.
It would be really interesting to see how small it could stay whilst adding in support for OpenGL.
It was a RTS game and quite cool, Arena Wars.
Re: Building a self-contained game in C# under 2 kilobytes
#26Sadly the video won’t play on my iPhone
https://migeel.sk/blog/2024/01/02/building-a-self-contained-...
Re: Building a self-contained game in C# under 2 kilobytes
#27Re: Building a self-contained game in C# under 2 kilobytes
#28It 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.
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.
Re: Building a self-contained game in C# under 2 kilobytes
#29It 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.
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.
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?
Re: Building a self-contained game in C# under 2 kilobytes
#30Very cool. What are the practical implications for this? Would it ever be wise to deploy these techniques for a commercial program? Is the end result more memory efficient during execution?
A small binary size is at least useful when running code in web browsers via WASM. Granted, 2 KByte would be way below diminishing returns, but even a couple of hundred KBytes is rare with high level languages like C# which usually require a big runtime. Even "we care about binary size at all" would be a major step forward for most "professional" applications.