Understanding how to use Task and ValueTask

Ғылым және технология

Understanding the Whys, what’s, and when’s of ValueTask
devblogs.microsoft.com/dotnet...
ValueTask reference docs
docs.microsoft.com/en-us/dotn...
NuGet package for ValueTask
www.nuget.org/packages/System...
In this episode, Stephen Toub chats with Rich about ValueTask and how it might help reduce allocations and memory usage for your asynchronous .NET code.
[00:34] - What is ValueTask and why do we need it?
[05:22] - What is a good scenario for ValueTask?
[10:00] - What is IValueTask?
[12:14] - Why was the non-generic ValueTask introduced?
[13:54] - Does ValueTask offer cancellation?
[14:42] - What can you do with Task vs ValueTask?
[16:28] - What’s the uptake with ValueTask usage?
[18:28] - How does IAsyncEnumerable task advantage of ValueTask?
[21:11] - What other performance work is happening around allocations?

Пікірлер: 15

  • @Jason_Shave
    @Jason_Shave5 жыл бұрын

    I generally learn most from these when you have some code examples to go along with the discussion. It's very difficult to understand the examples without any reference. Consider doing another video with the various code scenarios Rich has provided (there are many!).

  • @AdamsTaiwan

    @AdamsTaiwan

    5 жыл бұрын

    I agree. You might like this video: kzread.info/dash/bejne/oH9pltVxZNu4gtY.html

  • @AnitShrestha

    @AnitShrestha

    4 жыл бұрын

    @@AdamsTaiwan I had just went through the video and was going to mentioned it. The presentation by Matt is excellent!

  • @guibirow
    @guibirow5 жыл бұрын

    Amazing stuff! This is the kind of topic you have to watch and re-watch a few times to grasp very well. I have read the blog post previously and the video helped a lot to understand some grey areas that I haven't understand properly. The video probably would be 1h long or more to talk through everything. Thanks again!

  • @philipmrch8326
    @philipmrch83265 жыл бұрын

    This is exactly what I needed haha, thanks for the great content as always!

  • @CrazySpin3
    @CrazySpin35 жыл бұрын

    I subscribed! Nice video and very informative

  • @saadbinsami4801
    @saadbinsami48012 жыл бұрын

    Hi, Can you guys do a comparative analysis on Memory and T [ ] ?

  • @mAcCoLo666
    @mAcCoLo6662 жыл бұрын

    How can the data be already there without a cache? If I make the same httpcall twice, the call will be async both times, will it not?

  • @AdamsTaiwan
    @AdamsTaiwan5 жыл бұрын

    Would like to see more examples. I have an app that takes a snapshot of folders/files(with hash codes) on an external drive, saves it to a DataSet then saves it to file or DB. To update I have 2 passes , first pass looks for files in the dataset that have been removed. Second pass checks file system for new or modified files. When I don't have access to the external drive, I can load the DataSet and perform searches or check to see if a set of files on my local drive exist in the DataSet. I'm looking for ways to speed up the process wherever I can.

  • @MorningSire
    @MorningSire2 жыл бұрын

    Oh I get it, so ValueTask means value/vask, not a value (type) task :\ I was damn confused about this name for a while

  • @ZintomV1
    @ZintomV13 жыл бұрын

    I don't understand, why provide an Async method that returns ValueTask if you know it's always going to return Synchronously? Why not just use a synchronous method instead.

  • @ehsanehsani2809

    @ehsanehsani2809

    2 жыл бұрын

    Imagine your ValueTask is run 99% sync and 1% async. for example you read a file once and after that others use it synchronously, you may not want to block your thread for that 1% time.

  • @kenichimori8533
    @kenichimori85335 жыл бұрын

    Multi Value Tasks.

  • @georgechakhidze8698
    @georgechakhidze86984 жыл бұрын

    Marc Gravel of StackOverflow disagrees, "Prefer ValueTask to Task": blog.marcgravell.com/2019/08/prefer-valuetask-to-task-always-and.html

  • @nenadvicentic

    @nenadvicentic

    3 жыл бұрын

    That blog post did not consider all edge cases (e.g. `Task.WaitAny/WaitAll`, unknown `IValueTaskSource` implementation). And even with it's narrow analysis, conclusion is lame "always use, even when breaking API, but don't await twice". I'm sure Stephen Toub who wrote most of the TPL and `ValueTask` knows a bit more about the topic.