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

2024 ж. 24 Нау.
49 798 Рет қаралды

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

Пікірлер
  • The April Fools video should just be a compilation of Nick waiting for the benchmarks to finish

    @krhek@krhekАй бұрын
    • Damn I already have an idea for april fools but this would have been amazing

      @nickchapsas@nickchapsasАй бұрын
    • I would actually have seen it more like this: A 10-minute video and then 9.5 minutes of advertising for his videos 😅

      @LogicException@LogicExceptionАй бұрын
    • haha, that honestly is such a great idea. Or he recommends all the LinkedIn terrible code snippets.

      @SoVeryTired@SoVeryTiredАй бұрын
  • Would have liked to see comparison between this and Hashset, not a list scan.

    @der.Schtefan@der.SchtefanАй бұрын
    • Same performance but different data structure characteristics

      @nickchapsas@nickchapsasАй бұрын
    • @@nickchapsas Do you mean the same performance between SearchValues and HashSet?

      @tommaple@tommapleАй бұрын
    • @@nickchapsas This is not true, maybe for list with few values

      @kahXimiro@kahXimiroАй бұрын
  • This man used the Rickroll URL as the test data. Well played.

    @sewer56lol@sewer56lolАй бұрын
    • I thought that's what it was! You know you've been on the internet for too long when you recognize the URL...

      @alexclark6777@alexclark6777Ай бұрын
    • Yup, you just remember it, ahahah. Be it start or end of it.

      @sewer56lol@sewer56lolАй бұрын
  • 6:21 I would've liked to have seen how HashSet with the appropriate StringComparer compared.

    @billy65bob@billy65bobАй бұрын
    • Same performance but different data structure

      @nickchapsas@nickchapsasАй бұрын
    • @@nickchapsas This is not true, maybe for list with few values

      @kahXimiro@kahXimiroАй бұрын
  • 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.

    @Dekon58@Dekon58Ай бұрын
  • 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.

    @JohnTasler@JohnTaslerАй бұрын
  • Could you make a video comparison about hashset please? 😊

    @meowaves@meowavesАй бұрын
  • 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.

    @MaxxDelusional@MaxxDelusionalАй бұрын
  • What's the point of testing `Contains` performance against an array and not against a hashset?

    @DotNetCookbook@DotNetCookbookАй бұрын
    • They are both converted in a span and performance is identical between an array and a hashset including ignore case cases.

      @nickchapsas@nickchapsasАй бұрын
    • @@nickchapsas Are you saying that array and hashset both have identical performance characteristics and are basically the same data type?

      @zachemny@zachemnyАй бұрын
    • ​@@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.

      @DotNetCookbook@DotNetCookbookАй бұрын
    • @@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Ай бұрын
    • @@TheSaltCracka I think people are asking not about iteration over a hashset (why would they?), but about comparison of HashSet.Contains vs SearchValues.Contains.

      @zachemny@zachemnyАй бұрын
  • please make a video about micrsoft garnet

    @moleee2@moleee2Ай бұрын
  • 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.

    @Aaron31056@Aaron31056Ай бұрын
  • What is the size of the array you tested?

    @anm3037@anm3037Ай бұрын
  • HashSet?

    @BearJewOo@BearJewOoАй бұрын
    • the main limitation is that it doesn't work with Span

      @vborovikov@vborovikovАй бұрын
    • Same performance but different data structure characteristics

      @nickchapsas@nickchapsasАй бұрын
  • 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.

    @_iPilot@_iPilotАй бұрын
  • 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.

    @LogicException@LogicExceptionАй бұрын
  • Is this already efficient if you only have one string?

    @garcipat@garcipatАй бұрын
  • 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.

    @alirezanet@alirezanetАй бұрын
  • 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?

    @michaelakin766@michaelakin766Ай бұрын
  • 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

    @user-oh4ez2ig1s@user-oh4ez2ig1sАй бұрын
  • 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.

    @thimok22@thimok22Ай бұрын
    • 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

      @ntohl@ntohlАй бұрын
    • 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

      @nickchapsas@nickchapsasАй бұрын
    • ​@@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).

      @thimok22@thimok22Ай бұрын
  • 6:02 random collection of words you say… hmm… 🤔😂

    @Foxsterdota@FoxsterdotaАй бұрын
  • 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.

    @ThekillingGoku@ThekillingGokuАй бұрын
  • How does it compare against a hashset?

    @urbanelemental3308@urbanelemental3308Ай бұрын
    • They have identical performance

      @nickchapsas@nickchapsasАй бұрын
  • I just dont understand the different of the searchValue with the HashSet

    @polzaoops90@polzaoops90Ай бұрын
  • Does this cost on startup?

    @talwald1680@talwald1680Ай бұрын
    • Yeah that’s where the overhead is

      @nickchapsas@nickchapsasАй бұрын
  • What with Hashset?

    @Invudeal@InvudealАй бұрын
    • Same perf

      @nickchapsas@nickchapsasАй бұрын
  • Earlier video : Dont micro optimize! This video : This is 6 nano seconds faster! 😄😄👍

    @SirBenJamin_@SirBenJamin_Ай бұрын
    • This actually scales insanely well so you can save micro to milliseconds depending on the size of the collection

      @nickchapsas@nickchapsasАй бұрын
  • 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. 😊

    @kinsondigital@kinsondigitalАй бұрын
  • I know that ID too well lmao

    @NickMaovich@NickMaovichАй бұрын
    • HAHAHHAAHAHHAHAHA

      @nickchapsas@nickchapsasАй бұрын
  • Add a benchmark using dictionary and set to store the values and test contains on them

    @DanGolick@DanGolickАй бұрын
    • yeah was expecting to see that one in the benchmarks.

      @utubekade@utubekadeАй бұрын
    • HashSet I think would make more sense for this comparison

      @99MrX99@99MrX99Ай бұрын
    • For smaller sizes arrays will always be faster

      @metaltyphoon@metaltyphoonАй бұрын
  • FURST!!!!

    @nunyabuziness2700@nunyabuziness2700Ай бұрын
KZhead