5 ms·
Native AOT will come with .NET 7 https://devblogs.microsoft.com/dotnet/performance_improvements_in_net_7/#native-aot https://devblogs.microsoft.com/dotnet/perf
by giancarlostoro 4y ago
Native AOT will come with .NET 7
https://devblogs.microsoft.com/dotnet/performance_improvements_in_net_7/#native-aot https://devblogs.microsoft.com/dotnet/performance_improvemen...
> Native AOT is different. It’s an evolution of CoreRT, which itself was an evolution of .NET Native, and it’s entirely free of a JIT. The binary that results from publishing a build is a completely standalone executable in the target platform’s platform-specific file format (e.g. COFF on Windows, ELF on Linux, Mach-O on macOS) with no external dependencies other than ones standard to that platform (e.g. libc). And it’s entirely native: no IL in sight, no JIT, no nothing. All required code is compiled and/or linked in to the executable, including the same GC that’s used with standard .NET apps and services, and a minimal runtime that provides services around threading and the like.
Of course it does have some downsides:
> It also brings limitations: no JIT means no dynamic loading of arbitrary assemblies (e.g. Assembly.LoadFile) and no reflection emit (e.g. DynamicMethod), everything compiled and linked in to the app means the more functionality that’s used (or might be used) the larger is your deployment, etc. Even with those limitations, for a certain class of application, Native AOT is an incredibly exciting and welcome addition to .NET 7.
I wonder how things like ASP .NET will run with Native AOT in the future.
- fabian2k 4y agoI think typical ASP.NET applications likely won't use AOT in the near future. There is quite some "magic" in ASP.NET that I suspect won't work out of the box with AOT because it is heavily reflection-based. And while there are solutions for cases like JSON serialization, as far as I understand they require writing different code right now, so it's not automatic. AOT is much, much more interesting for cases where startup time matters, and ASP.NET usually isn't such a case. But I can imagine that it will be much more useful and easier to implement for smaller, focused tools that don't use that much reflection-based framework code. CLI tools might be the ideal case for trying this out.
- ewjt 4y agoServerless hosting (ie. AWS Lambda) makes ASP.NET a primary use case for AOT because cold startup times cripple performance and increase cost. I suspect they’re just not ready yet and targeting the easy use cases (console apps).
- romanhn 4y agoAs someone writing a .NET-based API hosted on AWS Lambda, I assure you, startup time matters a ton. I spent a bunch of time getting cold start time down to a semi-reasonable number, but there's still a ton of room for improvement. I for one am very much looking forward to progress on AOT Native.
- tmitchel2 4y agoLol snap
- fnord123 4y agoNo, snap startups have an even worse startup time.
- SideburnsOfDoom 4y agoAs someone writing a .NET-based API hosted on AWS Lambda, your case is quite different to a "typical ASP.NET hosted application", that can run for days between restarts.
- ledgerdev 4y agoI would like to host .net based api on google cloud run and azure container apps, which often will go to sleep after about 10 minutes without a request, so cold start time do matter quite a bit. I've done pretty extensive testing and see ~4-7 second cold starts with classic non aot mvc versus ~500ms with natively compiled golang/.net. The reality of the cloud is that sleep & cold starts are very common and in fact necessary to run efficient systems. Half a second is acceptable but 4+ seconds is not and so aot is very important for future apps.
- fabian2k 4y agoThe "typical" in my comment was meant to take care of that part, I probably should have mentioned this explicitly. AWS Lambda is of course a case where startup time matters a lot, but it still leaves the common problem of ASP.NET that it was designed around a lot of reflection. My understanding is that this simply won't work with AOT out of the box unless you adapt all the places where you use reflection-based code. For example you'd need to use the source generator versions of JSON serialization and the EF Core DbContext in this case, with all limitations those have. But I'm not sure my understanding here is entirely correct or complete.
- tmitchel2 4y agoUsing ASP.NET with AWS Lambda or any other FAAS is a concrete scenerio. Startup time for that is critical.
- SideburnsOfDoom 4y ago> I wonder how things like ASP .NET will run with Native AOT in the future. Let me give an example of an ASP.NET app lifecycle: an instance is launched, goes through startup code once. When it reports itself healthy, it is put into the Load balancer and then starts handling requests. Code in these paths is executed anywhere from occasionally to 1000s of times per second. After around 24 hours of this, it is shut down and restarted automatically. So, compiler micro-optimising startup code to take ms off of it, is not interesting at all - it's only run once a day. Startup can take whole seconds, it makes little difference, the instance is ready when it's done. AOT in general isn't that important, but automatic tiered compilation based on usage data is very nice.
- ewjt 4y agoServerless. Running an ASP.NET app in AWS Lambda is just a few lines of code. However, all of a sudden startup time becomes important for both performance and cost. These investments by Microsoft and others[1] allow .NET to remain relevant and viable for modern use cases. [1] https://github.com/awslabs/dotnet-nativeaot-labs https://github.com/awslabs/dotnet-nativeaot-labs
- SideburnsOfDoom 4y agoServerless is great, but if you want to go that route you should be aware that it is in no way a typical hosted ASP.NET app, and while you can "Run an ASP.NET app in AWS Lambda" with little code, there are are better ways to design a Lambda.
- ewjt 4y agoCan you elaborate on “is in no way a typical hosted ASP.NET app”? I get that the machinery under the hood is different (ie. Kestrel web server may not get used). However, we typically don’t care about those details. Our ASP.NET code runs in 3 separate places (containers, servers, Lambda) and the only difference between all 3 is a single entry point file. Do you mean because Lambda is only serving one request at a time and has a more ephemeral host process lifetime?
- pjmlp 4y agoFinally, I always though NGEN was a bad compromise and full AOT should have been supported since .NET 1.0, specially given Delphi's influence.
- geodel 4y agoGood. Java is doing something similar with Graal Native Image thing. In a way it is funny to see few years back so many people were claiming that heavy CPU/memory usage of JIT based platforms would be even more non-issue in Cloud because one can scale as much they need on demand. And now I see AOT/Slimmed Runtime/Compact packaging are happening largely because of cloud deployments. Seems cloud bills are making impact in places where enterprise cloud architects were running amok with everything micro service deployments.
- pjmlp 4y agoActually I think it is more competition pressure of languages like Go and Rust than anything else. I have been using Java and .NET languages for distributed computing for the last two decades, and JIT has always been good enough. By the way, Google rolled back their AOT compiler introduced on Android 5, and since Android 7 it uses a mix of highly optimized interpreter written in Assembly, a JIT compiler with PGO feedback, and when the device is idle, those PGO profiles are used to only AOT compiler the application flows that matter. On more recent Android versions, those PGO profiles are shared across devices via the Playstore. On the .NET front, I think the team has finally decided to make front of the whole C++ rulez of WinDev, specially after Singularity and Midori projects having failed to change their mind.
- geodel 4y agoNowadays Go is working on a PGO solution, so there is that. I don't disagree but kinda doubt that new upstart languages with single digit market and mindshare in enterprise space would force .net /JVM behemoth to do anything. Forget Go, places I work would not know a single new thing beyond Java 1.7 or latest Java 1.8. But they have stood up a dozen cloud teams doing every buzzword you can hear about cloud. So unless finance guys ask tough questions about rising Amazon billing IT wouldn't care if their SpringBoot crapola take 2GB of RAM or 32GB.
- pjmlp 4y agoThe new upstart languages are where the younger generations are, that is why you see .NET doing all those changes to make rolling an Hello World website as easy as doing it in Go, with global usings, single file code, simplified namespaces and naturally AOT.
- ledgerdev 4y agoIt definitely will eventually, probably .net8 timeframe. It will be hard to support so many dynamic features and no doubt will make extensive use of Source Generators. https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/so... Anyone have any interest in a small c# aot micro web framework that cold starts up fast (~500ms, vs ~4s for non aot mvc) on serverless containers like google cloud run?
- davidfowl 4y agoWe've been experimenting with NativeAOT for years with ASP.NET Core (which does runtime code generation all over the place). The most promising prototypes thus far are: - https://github.com/davidfowl/FasterActions https://github.com/davidfowl/FasterActions - https://github.com/davidfowl/uController https://github.com/davidfowl/uController They are source generated version of what ASP.NET does today (in both MVC and minimal APIs). There are some ergonomic challenges with source generators that we'll likely be working through over the coming years so don't expect magic. Also its highly unlikely that ASP.NET Core will not depend on any form of reflection. Luckily, "statically described" reflection generally works fine with NativeAOT. Things like configuration binding, DI, Logging, MVC, JSON serialization all rely on some form of reflection today and it will be non-trivial to remove all of it but we can get pretty far with NativeAOT if we accept some of the constraints. As of right now, we're trying to make sure "motivated people" can play with it, but it's not something that is supported by ASP.NET Core or EF at the moment. https://github.com/dotnet/aspnetcore/pulls?q=is%3Apr+nativeaot+is%3Aclosed https://github.com/dotnet/aspnetcore/pulls?q=is%3Apr+nativea... PS: Some of the challenges https://github.com/dotnet/aspnetcore/issues/42221 https://github.com/dotnet/aspnetcore/issues/42221
- merb 4y agoActually system text json does work with source generators and di can work with source Generators aswell.
- davidfowl 4y agoThanks for telling me :). On a serious note though, anything can work with source generators but it doesn't match the style of coding that we'd like (moving everything to be declarative isn't the path we want to go down for certain APIs). Also source generators don't compose, so any source generation that we would want to use would need to take advantage of the JSON source generator (if we wanted to keep things NativeAOT safe). Right now most of the APIs you use in ASP.NET Core are imperative and source generators cannot change the callsite so you need to resort to method declarations and attributes everywhere. That's not an optimization, that's a programming model change.
- lvass 4y agoI just can't help laughing profusely whenever I see MS doing a Native something. Don't you folks remember Native HTML5? https://www.youtube.com/watch?v=9mXe9nRiPHI https://www.youtube.com/watch?v=9mXe9nRiPHI