The Fastest Way to Search Gets Even Better in .NET 9
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
The April Fools video should just be a compilation of Nick waiting for the benchmarks to finish
Damn I already have an idea for april fools but this would have been amazing
I would actually have seen it more like this: A 10-minute video and then 9.5 minutes of advertising for his videos 😅
haha, that honestly is such a great idea. Or he recommends all the LinkedIn terrible code snippets.
Would have liked to see comparison between this and Hashset, not a list scan.
Same performance but different data structure characteristics
@@nickchapsas Do you mean the same performance between SearchValues and HashSet?
@@nickchapsas This is not true, maybe for list with few values
This man used the Rickroll URL as the test data. Well played.
I thought that's what it was! You know you've been on the internet for too long when you recognize the URL...
Yup, you just remember it, ahahah. Be it start or end of it.
6:21 I would've liked to have seen how HashSet with the appropriate StringComparer compared.
Same performance but different data structure
@@nickchapsas This is not true, maybe for list with few values
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.
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.
Could you make a video comparison about hashset please? 😊
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.
What's the point of testing `Contains` performance against an array and not against a hashset?
They are both converted in a span and performance is identical between an array and a hashset including ignore case cases.
@@nickchapsas Are you saying that array and hashset both have identical performance characteristics and are basically the same data type?
@@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.
@@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
@@TheSaltCracka I think people are asking not about iteration over a hashset (why would they?), but about comparison of HashSet.Contains vs SearchValues.Contains.
please make a video about micrsoft garnet
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.
What is the size of the array you tested?
HashSet?
the main limitation is that it doesn't work with Span
Same performance but different data structure characteristics
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.
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.
Is this already efficient if you only have one string?
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.
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?
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
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.
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
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
@@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).
6:02 random collection of words you say… hmm… 🤔😂
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.
How does it compare against a hashset?
They have identical performance
I just dont understand the different of the searchValue with the HashSet
Does this cost on startup?
Yeah that’s where the overhead is
What with Hashset?
Same perf
Earlier video : Dont micro optimize!
This video : This is 6 nano seconds faster!
😄😄👍
This actually scales insanely well so you can save micro to milliseconds depending on the size of the collection
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. 😊
I know that ID too well lmao
HAHAHHAAHAHHAHAHA
Add a benchmark using dictionary and set to store the values and test contains on them
yeah was expecting to see that one in the benchmarks.
HashSet I think would make more sense for this comparison
For smaller sizes arrays will always be faster
FURST!!!!