Finally someone who knows how to explain clearly. I watched other videos and couldn't comprehend why we need this ValueTask. But thanks to your clear explanation in 10 mins it all makes sense. Thanks a lot.
I have spend almost the whole evening to understand how they differ through Microsoft blogpost, and I couldn't figure it out. Thanks for your video, I have completely understood.
Holy cow! I was wondering the difference. So I googled it, found an article on MS blog. Did not get it. At some point there was an exemple but I could not compare because, thought there was a chapter on Task before, there was no equivalent of the example. But probably mostly because it downs clarity in too many details I could not comprehend. Maybe because of a lack of background. But here it is exactly what I need to comprehend. Right to the point as I like, good example. Simple definition. By 4mn of the video (even before) I got the point of those. Very much thank you for that.
thank you so much this cleared it up for me. Great explanation right to the point very easy to understand. First time I found your channel. It was the video after a Nick chapsas video in the search. Who I also enjoy. For that reason I have subscribed. I’m looking forward to future videos. Thank you Brian.
Compiler hot paths are code execution paths in the compiler in which most of the execution time is spent, and which are potentially executed very often. The reason for avoiding (heap) allocations in these code paths is that allocations may trigger a garbage collection, which may cause sudden, extreme performance deteriorations. These should obviously be avoided in very commonly executed code paths. Stack Overflow.
Hi Brian , grt video n best explanation for value task. Thanks for your help . I have an question might sound silly n apologise in advance. What exactly synchronisation context mean . Why ppl say AspNet core doesn’t support Synchronization context ??
Every thread has a context associated with it. The SynchronizationContext represents the location where your code is executed. It enables you to queue a task onto another context and it facilitates communication between threads. This is common used when communicating between a background thread and a UI thread (for example in WPF or WInForms). ASP.NET doesn't have a UI thread to be concerned with, and it literally does not have a SynchronizationContext class.
Hello Brian, Thanks so much for your work. I have the question about ValueTask limitations: You said we should not run the valuetaskMethod concurrently, but when i check the Paralle.ForeachAsyn method it accept a delegate that return ValueTask. so the delegate is called multiple times ? can you help me to clearify that. Thanks so much.
Hi Brian, could you create a video on best practises to manage data access within a blazor/c# app, without Entity Framework. I am think of this for a long time now but I don't find any solution where I say this is the perfect one. E.G. why should I use a service to access the data instead of a static method of my actual object?
@@BrianLagunas yes. I searched for this topic a while and I can only find examples regarding EF online. But I cannot use this in our project. I'm limited to writing the SQ myself. I am looking for best practises for Create/Update/Delete/Get + other method to fetch data from the database which require data from my model to run.
Nice explanation! I've a question for you... I started programming many years ago and since university studies or higher level professional training most of my programming teachers reinforce me the idea of using descriptive name and explicitly typed variables. As you can see on that time var was "forbidden". C#3.0 introduced var and C#8.0 has made nullable vars too... In dictionaries or local variables could help in readability and so..., instead you must initialize var variables and cannot assign an anonymous method to var or declare for example... Give me some light please... What's the point here¿? Thanks Brian!
My advice would be, use var if you like it. I like it and use it for most of my local variables. It helps keep my code clean and concise. I like to reduce redundant type information. It's shorter, easier to read, and it encourages descriptive names for your variables. Var is extremely helpful when dealing with LINQ queries too. But, it's just a personal preference. Use what you are comfortable with. The important part is that you be consistent in your code base.
Sometimes i need to make sure a method is only executed once at a time by only one thread and kills everyone else that wants to get in. so i add a global bool as some sort of lock at the beginning and set it back once i exit the method. I know there’s also mutex’s for these issues, but i wonder whats really the best solution
Wait... are the benchmark results consistent even if you run them a few times? Without having tested this myself, so just going from what I see in the video (@6:30): Both GetReposAsyncTask and GetReposAsyncValueTask use the same cache object. So isn't it possible the first benchmark (which happened to be the first method) populates the cache and the second method never even goes out to Github and ONLY serves results from cache (since the other method already populated the cache)? That would also explain **a** (maybe not the entire ~20Mb) difference in allocated memory.
@@BrianLagunas Ah, ok. I just had a hunch the _cachedRepos was maybe shared between the tests which is definitely at the very least a "gotcha" / something to look out for / be mindful of. Nice to hear and have confirmed in this case it's not. Thanks for the video!
@@BrianLagunas if the access to the cache were async too (as in distributed cache), then will ValueTask still make a difference? You can argue that the result involves async calls regardless.
When having large numbers like 100000 it's easier to read it if you write it as 100_000. The compiler will make that 10000 and it's easier to read in my opinion
I guess I’ve been doing this so long, I don’t ever use that syntax. My eyes are just used to reading those numbers 😁. I’ll keep that In mind for demos going forward. Others my not read those numbers as easily. Thanks for the feedback.
It is like answering to question What is ValueTask, others return a Task and only Brian returns a VALUE immediately. Thank you, Brian.
Very Clever! I love it!
Haha I see what you did there ;D
Best explanation on the internet in this topic
Thank you so much.
Finally someone who knows how to explain clearly. I watched other videos and couldn't comprehend why we need this ValueTask. But thanks to your clear explanation in 10 mins it all makes sense. Thanks a lot.
Glad you liked it!
The best explanation I've seen for valuetask, explained in language I understood. Thank you
I'm glad I could help clarify it. Thanks for watching
I have spend almost the whole evening to understand how they differ through Microsoft blogpost, and I couldn't figure it out. Thanks for your video, I have completely understood.
I’m glad I could help. Thank you for watching
The best explanation I've seen for valuetask
I’m glad it was helpful
Holy cow!
I was wondering the difference. So I googled it, found an article on MS blog. Did not get it. At some point there was an exemple but I could not compare because, thought there was a chapter on Task before, there was no equivalent of the example. But probably mostly because it downs clarity in too many details I could not comprehend. Maybe because of a lack of background.
But here it is exactly what I need to comprehend. Right to the point as I like, good example. Simple definition.
By 4mn of the video (even before) I got the point of those.
Very much thank you for that.
I’m happy I could help. Thanks for watching
You explained the best, out of a few that I have seen on RUclips.
Thank you for the kind words
Finally a definitive explanation, thank you very much for your help!
You’re very welcome. Thank you for watching
Awesome explaination. I failed to understand other explainations of this type but yours was clear and easy to understand.
This is why I consider u as my guru🙏🙏 explanation is crystal clear 👌
Thank you so much for the kinds words sir
That was a really good explanation, Brian!
Thank you.
Another brilliant video, hope you will come back to teach us more! Thank you
thank you so much this cleared it up for me. Great explanation right to the point very easy to understand. First time I found your channel. It was the video after a Nick chapsas video in the search. Who I also enjoy. For that reason I have subscribed. I’m looking forward to future videos. Thank you Brian.
What a teacher! Thank you a lot for your excellent explanation!
Thank you so much for the kind words
Great explanation Brian, thank you!
...But wait a second, where is "roll dat intro"?
Thank you for watching. Yeah, I'm dropping the intro stuff as I dont think it provides any value. I'll just get to the point 😁
Excellent summary.
Thank you for watching
Very clear explanation, thank you!
Thanks for watching
This was a great explanation! Thank you!
Compiler hot paths are code execution paths in the compiler in which most of the execution time is spent, and which are potentially executed very often.
The reason for avoiding (heap) allocations in these code paths is that allocations may trigger a garbage collection, which may cause sudden, extreme performance deteriorations. These should obviously be avoided in very commonly executed code paths. Stack Overflow.
Isn't that what I said? 😀
Excellent explanation!
Thank you very much
Thanks for explanation, this is the clearest.
Thank you for watching
Very nice video and great demonstration.
Thanks for watching.
Thanks a lot on this Brian.
You’re welcome
Good presentation.
I appreciate you
Good explanation. Thank you!!
Thank you for watching
Ctrl +shift + f Task
Replace all with ValueTask 😅
Most of the time I use Task
Nice explanation 👍🏻👍🏻
Haha! When in doubt, Task is the go to. Thanks for watching
Thank you! I don't know that it could bring that performance, especially memory usage
Thanks for watching
Great explaination
Thanks for watching
Thanks for the great explanation. What happens if we use valuetask when the return type is always a task?
Hi Brian , grt video n best explanation for value task. Thanks for your help .
I have an question might sound silly n apologise in advance.
What exactly synchronisation context mean . Why ppl say AspNet core doesn’t support Synchronization context ??
Every thread has a context associated with it. The SynchronizationContext represents the location where your code is executed. It enables you to queue a task onto another context and it facilitates communication between threads. This is common used when communicating between a background thread and a UI thread (for example in WPF or WInForms). ASP.NET doesn't have a UI thread to be concerned with, and it literally does not have a SynchronizationContext class.
Isn't the cache filled in the first method, meaning that the second benchmark is using cache only?
best explanation! Thank you!
Thanks for watching
Thanks, that's a nice clear explanation.
Glad it was helpful!
Thanks man, finally got it!
Great to hear
I love your videos mate! Thanks a lot
Thanks for watching
Hello Brian, Thanks so much for your work. I have the question about ValueTask limitations:
You said we should not run the valuetaskMethod concurrently, but when i check the Paralle.ForeachAsyn method it accept a delegate that return ValueTask. so the delegate is called multiple times ? can you help me to clearify that. Thanks so much.
Thanks a lot Brian 👍
Very welcome
Could you make a video explaining how attributes work and how to create custom ones?
Good video, I have a question though. I can't picture any instance where I'd await a task more than once, can you give an example?
Loading files from disk is a common one.
@@BrianLagunas Thanks :)
Ottima spiegazione.
Grazie
This is great stuff.
I appreciate the kind words
Hi Brian,
could you create a video on best practises to manage data access within a blazor/c# app, without Entity Framework.
I am think of this for a long time now but I don't find any solution where I say this is the perfect one. E.G. why should I use a service to access the data instead of a static method of my actual object?
That's a really broad topic. I'll have to think about that one. I will say that you should never use static anything for data access.
@@BrianLagunas yes. I searched for this topic a while and I can only find examples regarding EF online. But I cannot use this in our project. I'm limited to writing the SQ myself. I am looking for best practises for Create/Update/Delete/Get + other method to fetch data from the database which require data from my model to run.
Awesome!
Glad you think so!
simple, clear explaination and good benchmark/demo, thanks you ~ but I think this video can be shorter, 5mins top.
eXcellently explained.
Thank you so much
Would love an explanation around yield return
Thanks for the feedback
Nice explanation! I've a question for you... I started programming many years ago and since university studies or higher level professional training most of my programming teachers reinforce me the idea of using descriptive name and explicitly typed variables. As you can see on that time var was "forbidden". C#3.0 introduced var and C#8.0 has made nullable vars too... In dictionaries or local variables could help in readability and so..., instead you must initialize var variables and cannot assign an anonymous method to var or declare for example... Give me some light please... What's the point here¿? Thanks Brian!
My advice would be, use var if you like it. I like it and use it for most of my local variables. It helps keep my code clean and concise. I like to reduce redundant type information. It's shorter, easier to read, and it encourages descriptive names for your variables. Var is extremely helpful when dealing with LINQ queries too. But, it's just a personal preference. Use what you are comfortable with. The important part is that you be consistent in your code base.
Excelent video! The best explanation!
Thanks for watching
thanks
Thanks for watching
Can we consider ValueTask for singleton service method?
If the method can run either async or sync and you have benchmarked your method to determine that you would benefit from using it, then sure.
Make a sample code of application using Ivaluetaskasync any example please
Sometimes i need to make sure a method is only executed once at a time by only one thread and kills everyone else that wants to get in. so i add a global bool as some sort of lock at the beginning and set it back once i exit the method. I know there’s also mutex’s for these issues, but i wonder whats really the best solution
If I understand you correctly, I'm pretty sure this is what the "lock" statement is for.
Thanks you man
Thank you for watching
Wait... are the benchmark results consistent even if you run them a few times? Without having tested this myself, so just going from what I see in the video (@6:30): Both GetReposAsyncTask and GetReposAsyncValueTask use the same cache object. So isn't it possible the first benchmark (which happened to be the first method) populates the cache and the second method never even goes out to Github and ONLY serves results from cache (since the other method already populated the cache)? That would also explain **a** (maybe not the entire ~20Mb) difference in allocated memory.
No. I tested this myself to be sure. The Benchmark harness executes each test individually as a new instance of the benchmark class.
To be extra sure, I even changed the order in which the test invoke (ValueTask first) and the results were the same.
@@BrianLagunas Ah, ok. I just had a hunch the _cachedRepos was maybe shared between the tests which is definitely at the very least a "gotcha" / something to look out for / be mindful of. Nice to hear and have confirmed in this case it's not. Thanks for the video!
@@BrianLagunas Great! Again, nice to have this confirmed / double-checked ;-)
@@BrianLagunas if the access to the cache were async too (as in distributed cache), then will ValueTask still make a difference? You can argue that the result involves async calls regardless.
Can you show, when using ValueTask can be worst than Task?
I actually covered it in this video. If you have a method that whose "hot path" is not pulling from cache, then you are better off just using Task
When having large numbers like 100000 it's easier to read it if you write it as 100_000. The compiler will make that 10000 and it's easier to read in my opinion
I guess I’ve been doing this so long, I don’t ever use that syntax. My eyes are just used to reading those numbers 😁. I’ll keep that In mind for demos going forward. Others my not read those numbers as easily. Thanks for the feedback.