The Fastest Way to Search Gets Even Better in .NET 9

Sdílet
Vložit
  • čas přidán 24. 03. 2024
  • Use code CLEAN15 and get 15% off the brand new "From Zero to Hero: Writing Clean Code with C#" course on Dometrain: dometrain.com/course/from-zer...
    Become a Patreon and get special perks: / nickchapsas
    Hello, everybody, I'm Nick, and in this video I will show you how .NET 9 improves the SearchValues class to make it one of the most useful classes of the .NET 9 release.
    Workshops: bit.ly/nickworkshops
    Don't forget to comment, like and subscribe :)
    Social Media:
    Follow me on GitHub: github.com/Elfocrash
    Follow me on Twitter: / nickchapsas
    Connect on LinkedIn: / nick-chapsas
    Keep coding merch: keepcoding.shop
    #csharp #dotnet

Komentáře • 76

  • @krhek
    @krhek Před měsícem +95

    The April Fools video should just be a compilation of Nick waiting for the benchmarks to finish

    • @nickchapsas
      @nickchapsas  Před měsícem +32

      Damn I already have an idea for april fools but this would have been amazing

    • @LogicException
      @LogicException Před měsícem +1

      I would actually have seen it more like this: A 10-minute video and then 9.5 minutes of advertising for his videos 😅

    • @SoVeryTired
      @SoVeryTired Před měsícem

      haha, that honestly is such a great idea. Or he recommends all the LinkedIn terrible code snippets.

  • @der.Schtefan
    @der.Schtefan Před měsícem +34

    Would have liked to see comparison between this and Hashset, not a list scan.

    • @nickchapsas
      @nickchapsas  Před měsícem

      Same performance but different data structure characteristics

    • @tommaple
      @tommaple Před měsícem

      @@nickchapsas Do you mean the same performance between SearchValues and HashSet?

    • @kahXimiro
      @kahXimiro Před měsícem

      @@nickchapsas This is not true, maybe for list with few values

  • @sewer56lol
    @sewer56lol Před měsícem +39

    This man used the Rickroll URL as the test data. Well played.

    • @alexclark6777
      @alexclark6777 Před měsícem +2

      I thought that's what it was! You know you've been on the internet for too long when you recognize the URL...

    • @sewer56lol
      @sewer56lol Před měsícem +1

      Yup, you just remember it, ahahah. Be it start or end of it.

  • @billy65bob
    @billy65bob Před měsícem +6

    6:21 I would've liked to have seen how HashSet with the appropriate StringComparer compared.

    • @nickchapsas
      @nickchapsas  Před měsícem +2

      Same performance but different data structure

    • @kahXimiro
      @kahXimiro Před měsícem

      @@nickchapsas This is not true, maybe for list with few values

  • @Dekon58
    @Dekon58 Před měsícem +2

    I believe it was crucial to compare performance, including the caching aspect of the SearchValues, or at least to demonstrate it explicitly. Yes, caching something that will be used multiple times is obviously faster. The most common use case would be to validate an input only once, such as with the IsBase64 example. It doesn't make sense to cache an input for a one-time validation.

  • @JohnTasler
    @JohnTasler Před měsícem +2

    I would've liked to see Benchmark on a much, much larger SearchArray of words. Take a book and tokenize it, for example. Then have benchmarks for the first word, middle word, last word, and not-in-set.

  • @meowaves
    @meowaves Před měsícem +2

    Could you make a video comparison about hashset please? 😊

  • @MaxxDelusional
    @MaxxDelusional Před měsícem +1

    Can this be translated to SQL in a Linq expression? For example:
    SearchValues mySearchValues = SearchValues.Create(["john", "paul"]), StringComparisionType.OrdinalIgnoreCase);
    var result = await dbSet.Where(x => mySearchValues.Contains("ringo").ToListAsync();
    I know this would negate the performance of using SearchValues, but it would be nice to be consistent with how we write this type of code. Ideally the translator could even use the string comparison type to modify the collation of the query.

  • @DotNetCookbook
    @DotNetCookbook Před měsícem +16

    What's the point of testing `Contains` performance against an array and not against a hashset?

    • @nickchapsas
      @nickchapsas  Před měsícem +5

      They are both converted in a span and performance is identical between an array and a hashset including ignore case cases.

    • @zachemny
      @zachemny Před měsícem +1

      @@nickchapsas Are you saying that array and hashset both have identical performance characteristics and are basically the same data type?

    • @DotNetCookbook
      @DotNetCookbook Před měsícem +4

      ​@@nickchapsas first of, `Array.Contains` utilizes spans only for primitive value types, not for strings. Second of all, even for value types, how would this make sense? It is still a linear search vs a constant. To be clear, I am referring to the latter example where you are searching for a word, because this is the most realistic use case.

    • @zachemny
      @zachemny Před měsícem

      @@TheSaltCracka I think people are asking about comparison of HashSet.Contains() which is used now for searching strings vs SearchValues.Contains() and not about iteration

    • @zachemny
      @zachemny Před měsícem

      @@TheSaltCracka I think people are asking not about iteration over a hashset (why would they?), but about comparison of HashSet.Contains vs SearchValues.Contains.

  • @moleee2
    @moleee2 Před měsícem +2

    please make a video about micrsoft garnet

  • @Aaron31056
    @Aaron31056 Před měsícem +2

    I would love to see a comparison benchmark for different sizes of collections using searchvalues vs other common ways for that size of collection. Specifically for how it scales to very large collections.

  • @anm3037
    @anm3037 Před měsícem +1

    What is the size of the array you tested?

  • @BearJewOo
    @BearJewOo Před měsícem +5

    HashSet?

    • @vborovikov
      @vborovikov Před měsícem +1

      the main limitation is that it doesn't work with Span

    • @nickchapsas
      @nickchapsas  Před měsícem

      Same performance but different data structure characteristics

  • @_iPilot
    @_iPilot Před měsícem

    What features i wish to come to C#? Some of new interfaces added in .NET7 and placed into System.Numerics namespace to be applied to TimeSpan and DateTime.

  • @LogicException
    @LogicException Před měsícem +2

    It would be much more interesting as a benchmark if the text to be searched had been a real text and not just a word. So instead of "pewpew", "the sun shines on pewpew" etc. Then the benchmark would be more interesting, because you don't usually search for words in a 1:1 match, but also in a larger search space.

  • @garcipat
    @garcipat Před měsícem

    Is this already efficient if you only have one string?

  • @alirezanet
    @alirezanet Před měsícem +4

    I think the best place to use it is in the dotnet code itself! I am wondering why they're not optimizing methods like Contains internally. the overhead of creating this object and caching it can be handled on compile time.

  • @michaelakin766
    @michaelakin766 Před měsícem

    Question: You always show the system code implementation, but when I try to do that in Visual Studio, I only get "metadata". Does anyone know how to show the code implementation in Visual Studio?

  • @user-oh4ez2ig1s
    @user-oh4ez2ig1s Před měsícem

    i am going to buy your course for per month but at the end of buying it isn't showing me the option which i chose , it is throwing me for year option

  • @thimok22
    @thimok22 Před měsícem

    Unrelated question: why are you still using the old UI of Rider and haven't updated to the new UI yet? I'm curious, especially since I like the new UI ten times better than the old one.

    • @ntohl
      @ntohl Před měsícem

      I'm not Nick, but I instantly switched back to the old UI. Rider have so much features it belongs to some hierarchy that you ought to read the menu when you search for something. So I prefer reading menu points instead of learning the full ancient Egypt ABC

    • @nickchapsas
      @nickchapsas  Před měsícem

      I think I tried it too early and it wasn’t ready that that pushed me away so now I’m just waiting for the right time to update. I think I will move to it in the next release

    • @thimok22
      @thimok22 Před měsícem

      ​@@nickchapsasThat's completely fair. I didn't like the new layout in the beginning too. Now I think it's a great layout after they made some initial changes.
      Just beware, there is one specific option in the settings for the new layout. I don't know exactly what it's called, but it basically removes the top toolbar into a hamburger menu. I definitely don't like that option and have that turned off (or on? Idk in what direction the checkbox was).

  • @Foxsterdota
    @Foxsterdota Před měsícem

    6:02 random collection of words you say… hmm… 🤔😂

  • @ThekillingGoku
    @ThekillingGoku Před měsícem

    I'll try 'n remember it in 2 years for .NET10. By our policy we only use LTS framework releases, so NET9 will not end up on the books for any actual PRD code.

  • @urbanelemental3308
    @urbanelemental3308 Před měsícem

    How does it compare against a hashset?

  • @polzaoops90
    @polzaoops90 Před měsícem

    I just dont understand the different of the searchValue with the HashSet

  • @talwald1680
    @talwald1680 Před měsícem

    Does this cost on startup?

    • @nickchapsas
      @nickchapsas  Před měsícem +1

      Yeah that’s where the overhead is

  • @Invudeal
    @Invudeal Před měsícem

    What with Hashset?

  • @SirBenJamin_
    @SirBenJamin_ Před měsícem +2

    Earlier video : Dont micro optimize!
    This video : This is 6 nano seconds faster!
    😄😄👍

    • @nickchapsas
      @nickchapsas  Před měsícem +4

      This actually scales insanely well so you can save micro to milliseconds depending on the size of the collection

  • @kinsondigital
    @kinsondigital Před měsícem +1

    I actually know Guilherme Ferreira. Great guy and is also knowledgeable. I highly recommend the course if you want to write cleaner code.
    NOTE: I am not being paid for this comment in any way. Just my personal opinion. 😊

  • @NickMaovich
    @NickMaovich Před měsícem

    I know that ID too well lmao

  • @DanGolick
    @DanGolick Před měsícem +5

    Add a benchmark using dictionary and set to store the values and test contains on them

    • @utubekade
      @utubekade Před měsícem

      yeah was expecting to see that one in the benchmarks.

    • @99MrX99
      @99MrX99 Před měsícem +1

      HashSet I think would make more sense for this comparison

    • @metaltyphoon
      @metaltyphoon Před měsícem

      For smaller sizes arrays will always be faster

  • @nunyabuziness2700
    @nunyabuziness2700 Před měsícem

    FURST!!!!