Understanding how to use Task and ValueTask

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ก.ค. 2019
  • 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_Shave 5 ปีที่แล้ว +59

    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 ปีที่แล้ว +2

      I agree. You might like this video: th-cam.com/video/nK54s84xRRs/w-d-xo.html

    • @AnitShrestha
      @AnitShrestha 4 ปีที่แล้ว +1

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

  • @guibirow
    @guibirow 5 ปีที่แล้ว +5

    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
    @philipmrch8326 5 ปีที่แล้ว +3

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

  • @CrazySpin3
    @CrazySpin3 5 ปีที่แล้ว +1

    I subscribed! Nice video and very informative

  • @saadbinsami4801
    @saadbinsami4801 2 ปีที่แล้ว

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

  • @mAcCoLo666
    @mAcCoLo666 2 ปีที่แล้ว +1

    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
    @AdamsTaiwan 5 ปีที่แล้ว +3

    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
    @MorningSire 2 ปีที่แล้ว +1

    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
    @ZintomV1 3 ปีที่แล้ว +1

    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
    @kenichimori8533 5 ปีที่แล้ว +1

    Multi Value Tasks.

  • @georgechakhidze8698
    @georgechakhidze8698 4 ปีที่แล้ว +2

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

    • @nenadvicentic
      @nenadvicentic 3 ปีที่แล้ว +5

      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.