, 15 tweets, 3 min read
My Authors
Read all threads
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.
3/15 But .NET offers unconstrained reflection: one can `Type.GetType` a text string literally downloaded from the internet and call methods on that type
4/15 Thanks to the unconstrained reflection, determining a proper subset of methods a .NET program *can* call is pretty much the halting problem en.wikipedia.org/wiki/Halting_p…
5/15 AOT compiler has a strong incentive to only compile what's used. Native code tends to be bigger than the source IL: carrying dead code is more expensive
6/15 How does an AOT compiler decide what to compile? Turns out this problem also exists in non-AOT world - take IL Linker: hanselman.com/blog/MakingATi…
7/15 The easiest thing is to assume all the app code (including 3rd party NuGets) is used. FX/BCL is fair game: don't compile/keep if it's not visibly called.
8/15 In the rare case when this policy doesn't work, both IL Linker and AOT compilers have means (XML file) to specify other methods/types to compile/keep.
9/15 This policy makes a lot of existing code work, but comes with costs: we still keep/compile a lot of unreferenced code.
10/15 How expensive you ask? Last week I compiled a Blazor app with CoreRT in 5.5 MB, fully self-contained. I used the "compatible but big" setting.
11/15 This weekend I spent an hour debugging the Blazor app compiled without the compatiblity switch. ~20 lines of XML hints later, the Blazor app worked.
12/15 I call this mode the "hard mode" of CoreRT. One needs to do extra work, but gets rewarded with better perf numbers.
13/15 A fully self-contained x64 Blazor app compiled with CoreRT comes down to 3.5 MB (compressed). It also uses less memory as a bonus.
14/15 This mode is not for everyone, but it's good to have it when you really need it. It beats having to rewrite the app in Go/C to meet size/memory quotas.
15/15 Check out my branch that has two commits: the first commit adds CoreRT in "easy mode", the second commit enables "hard mode" github.com/MichalStrehovs…
Missing some Tweet in this thread? You can try to force a refresh.

Enjoying this thread?

Keep Current with Michal Strehovský

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!