Michal Strehovský Profile picture
I help building the .NET runtime at Microsoft. My tweets are my own opinions and/or shitposts, not the official party line.
Sep 9, 2022 4 tweets 2 min read
1/N One of my favorite optimizations in the upcoming .NET 7 Native AOT is static data preinitialization. This program prints a circle to the screen. Would you believe me if I said there is no code to compute the circle bytes in the NativeAOT'd executable file of this program?👇🧵 class Program {     static readonly byte[] s_bytes = Compute 2/N Main difference between Native AOT and the other forms of AOT in .NET is that Native AOT doesn't just pregenerate code - it generates all data structures necessary to run the code, including structures that describe layout of types in memory necessary to do things like run GC
Mar 30, 2020 12 tweets 4 min read
1/N I thought it might be interesting to look at how generics are compiled to native code in .NET. A thread. 2/N When generic code is stored in IL on disk (as produced by e.g. the C#/VB/F# compiler), single generic method has a single method body. This method body is only runnable on the abstract CPU that the .NET compilers target. To run it on real hardware, it has to be translated.
Jan 19, 2020 10 tweets 3 min read
1/n It has always bugged me that I can't run my 64-bit C# games on MS-DOS. Today I fixed that. A thread. 2/n Windows EXE files consist of two parts: a DOS program that prints "This program cannot be run in DOS mode", followed by a header that Windows understands.
Jan 9, 2020 7 tweets 2 min read
1/7 Did you ever need to run a piece of C# code on Windows 3.11? Me neither, but I did it anyway. A thread. 2/7 The key ingredient it setting your expectations low. This is the program I got running:
Jan 8, 2020 5 tweets 2 min read
1/5 How about a 2,121 byte version of the C# game? Still 100% self-contained. Here's what I did: 2/5 Implement enough x86 Windows support in CoreRT so that we can build the game for it (previous attempt was x64; but the x86 CPU instruction set is more compact): github.com/dotnet/corert/…
Dec 2, 2019 15 tweets 3 min read
1/15 When compiling .NET ahead of time, the hardest question to answer is what code to compile. 2/15 For many non-.NET languages it's enough to compile the closure of Main(): start with Main() and compile all methods called from there transitively.
Oct 18, 2019 6 tweets 2 min read
1/5 "Ugly side of default interface methods" time. Interface with two methods, one with a default implementation. What will the following program print? 2/5 If you guessed 21, you're right, but don't pop the champagne yet. Let's change "class Adder" to "struct Adder" - what will it print now?
Oct 13, 2019 5 tweets 2 min read
1/5 A little know C#/.NET fact is that one can end up in a situation where `this is null` evaluates to true. One just needs a bit of reflection. Image 2/5 There's good reasons why it's little known. For one, it's kind of useless. The other reason is that doing that starts breaking invariants. For example, C# assumes `this` is always non-null. Call to `this.AndAgain()` should throw, but it won't. ImageImage