Await Async Might Change Completely in .NET 9

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody I'm Nick and in this video I'm going to talk about a very interesting experiment that the net team is running for do net 99 that can completely change how a weight a sync Works in cop now this is building on top of the findings of a previous experiment that I don't team run and we're going to talk about that as well but you can see that Microsoft is trying to play around with the idea of how we've been doing a way they sync and improve it so in this video I'm going to show you what the experiment is what the findings of the previous experiment was and where we might be heading net 9 or maybe a future net version if you like content and you want to see more make sure you subscribe for more training check out my courses on Dom train.com okay so let's see what we have here there's a GitHub issue by the way everything will be linked down below if you want to have a look on your own but there's a GitHub issue with titled net 9 runtime acing experiment and we're going to talk about what that is but before we dive into that I want to quickly touch on the net 8 async experiment that Microsoft was trying out and it wasn't really an a think one directly but more of something called Green threads so I can go here and you can see there's the results of that green thread experiment where Microsoft tried to introduce a second sort of concurrency model in net for Nonio blocking operations that would live next to a weight a sync and there were tons of issues with that approach the idea was that you wouldn't write code that looks like a weable code or a weight a syn code you would write something like this where this looks like a synchronous call however behind the scenes this would be asynchronous and it wouldn't be blocking the io so the approach would be to give you a way to write synchronous code that actually behind the scenes is non-blocking and a synchronous now as you can understand this would completely change how C is written and also we have to live next to the existing async model because they wouldn't just remove a weight a sync and replace it with green threads you would have both so what happens if a code calls green threads what happens when green threads call Laing code how about performance as you can see over here there was a bit of a degradation in the experiments and so on there will be a link in the description down below if you want to take a look at this because the findings were very interesting but you can see that Microsoft has been playing around with the idea of having a different approach in doing a way they snc now before I go into this issue and start reading what's going on I want to show you how a way a sync code is translated and compiled because it's all about that in this specific experiment so if we go shop.io as you can see over here what I have is just a normal class and normal void method and then I have the lowered C which is sort of the lowlevel C that the high level one we're writing on the left will be translated into so if I turn this into an async task method then what you're going to see on the right hand side is tons of code being generated and all this code is written by the compiler to effectively support the AA sync model and and as you can see we have a brand new struct over here by the way this is struct if you're release mode but if you're debug mode this is class then you have an implementation of an interface you have this method Builder you have the move next iterator pattern you have all this code generated because this is all done on the C Level with C related structures you can basically write a we a sync with Rosy shop technically without the keyword now there is nothing fundamentally wrong with it but this came at a time where Microsoft couldn't really touch the run time of net because of the way it shipped so it had to be done and all the features had to be done in that lowering way now that they can change it you can see that now new features do change the CLR and how it works if we go back to that issue that experiment very much focuses on that in net 8 they tried something about green threads they learned a lot but they decided not to move forward with that so what's coming in do net 9 well in do net 9 they were trying to take what they learn and explore performance and usability improvements on the existing AWA sync threading model so don't introduce a new one but see how we can improve the existing one which I love because it is so confusing still for so many people to have an a theying model in C even though C pioneered this model so many questions still exist so the background here is from copet libr Level there's two threading models the OS threads and then the await and task approach then you have concurrent code that can access these models with the thread or the task do run respectively so in modern cop we are recommended to be using a sync and Tusk because dealing with threads can be very very hard now that experiment has its own GitHub repo or GitHub repo branch on the runtime lab repo which is where Microsoft is trying tons of things that eventually make it into runtime or get rejected so if you want to get a peek into the future that's what you should be looking at and as we can see over here that's the repos story and it has tons of work being done on it now the documentation page about the design can be found here under runtime handle tasks why are they called runtime handle tasks well because Microsoft what is trying to do is move away from the compiler generating all that lower cop code that doesn't really have any information on the ilil code itself or the runtime and move it there so so instead of the state machines being that c concept all that way they saying is moved into a runtime concept and in that report you can see that if you search for async 2 you're going to find plenty of methods using that new async 2 keyword as you can see over here for example which by the way won't be the one they eventually launch with it's just there so they can compare the two approaches but that's how they're representing this new approach and there's t tons and tons and tons of documentation you can read if you really want to go in depth this will be more of an introduction to make you aware of this just in case someone is familiar enough with the concept to go ahead try it out and also provide feedback I like to bring these things into your attention but know that this is happening now Microsoft is taking a look at this from a specific lens and that is first micro benchmarks how much does a weight cost you should know a weight is a pretty expensive keyword and when you can avoid it you really should because that state machine is L and you have to go through that theator pattern behind the scenes to actually move into the completed State now things like nested a weights and how does that affected things like frequent suspension or rare suspensions think about compatibility semantics cost of switching in an Ideal World this will all be transparent to you but I don't know how much of that will be the case and then of course iel size that inflation of moving that to the i what does that mean do we get a smaller footprint because now we have to lower less C sh up into I code to achieve the same thing and then how about cross gen and Native aot because Microsoft is really really focusing on making native aot work for.net in a very small package now in the issue itself there isn't much of interest but if you try to play around with it and you have feedback that's the place where you want to start leaving some comments but I want to quickly go into the repository itself and see some of the documentation and you can actually see that Microsoft let me just make this a bit smaller uh you can see that they've been pretty big on graphs in fact the latest commit over here is showing interations per second of calling acing methods and you can see over here async one that's the one that already exists in net the lower version and then you can see the performance difference that async to would have with a task returning method the jit State machine over here and then the unwinder model again not going to go into too much detail what you should know is that performance is very much in the Forefront of this project and by everything I've been reading until now it should be better so your C shop should get faster quote unquote should because we don't know yet assuming that this actually makes it and it is optimized because they are still very much in early stages this issue was raised I think all the way in the 10th of November and we have January 2024 now now the biggest goal of this experiment is can the runtime generated async State machine actually be substantially better in performance than the existing model because there's always risk into making a change like this such a fundamental change so what's the risk versus reward here and then the more interesting goal is find out if they can Implement A variation of async that async to a second way of doing async basically and that's the way I understand it which has some subtle semantic Behavior changes but remains compatible with existing code which is written in the original style so have two a tasing models or keywords and hopefully they can coexist and call each other and not have a big enough performance implication or break your existing code now there's comments and explanations or approaches on how this might be done but I find it extremely funny that we still going to have a configure away thing here this is going to be an attribute this time and I can't wait for all the stack Overflow questions on when should I use a configur weight attribute this time not the dot configure a weight method now this is as far as I want to go with this I want to leave it here I'm going to put all the links description down below if you want to go ahead and dive deeper into this read more and give some feedback to the Microsoft team because especially if something else is added next to a weight i s this will be a very very big change so Microsoft will definitely need as much feedback as they can get so check the link description try it out play around with it and let them know what you think well that's all I had for you for video thank you very much for watching and as always keep coding
Info
Channel: Nick Chapsas
Views: 86,076
Rating: undefined out of 5
Keywords: Elfocrash, elfo, coding, .netcore, dot net, core, C#, how to code, tutorial, development, software engineering, microsoft, microsoft mvp, .net core, nick chapsas, chapsas, dotnet, .net, c#, await async, .net await async, async, await, c# await async, Await Async Might Change Completely in .NET 9
Id: UMeKxBcNBE0
Channel Id: undefined
Length: 9min 55sec (595 seconds)
Published: Mon Jan 08 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.