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

  Рет қаралды 50,024

Nick Chapsas

Nick Chapsas

Ай бұрын

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

Пікірлер: 76
@krhek
@krhek Ай бұрын
The April Fools video should just be a compilation of Nick waiting for the benchmarks to finish
@nickchapsas
@nickchapsas Ай бұрын
Damn I already have an idea for april fools but this would have been amazing
@LogicException
@LogicException Ай бұрын
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 Ай бұрын
haha, that honestly is such a great idea. Or he recommends all the LinkedIn terrible code snippets.
@sewer56lol
@sewer56lol Ай бұрын
This man used the Rickroll URL as the test data. Well played.
@alexclark6777
@alexclark6777 Ай бұрын
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 Ай бұрын
Yup, you just remember it, ahahah. Be it start or end of it.
@der.Schtefan
@der.Schtefan Ай бұрын
Would have liked to see comparison between this and Hashset, not a list scan.
@nickchapsas
@nickchapsas Ай бұрын
Same performance but different data structure characteristics
@tommaple
@tommaple Ай бұрын
@@nickchapsas Do you mean the same performance between SearchValues and HashSet?
@kahXimiro
@kahXimiro Ай бұрын
@@nickchapsas This is not true, maybe for list with few values
@Dekon58
@Dekon58 Ай бұрын
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.
@billy65bob
@billy65bob Ай бұрын
6:21 I would've liked to have seen how HashSet with the appropriate StringComparer compared.
@nickchapsas
@nickchapsas Ай бұрын
Same performance but different data structure
@kahXimiro
@kahXimiro Ай бұрын
@@nickchapsas This is not true, maybe for list with few values
@JohnTasler
@JohnTasler Ай бұрын
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.
@MaxxDelusional
@MaxxDelusional Ай бұрын
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.
@anm3037
@anm3037 Ай бұрын
What is the size of the array you tested?
@meowaves
@meowaves Ай бұрын
Could you make a video comparison about hashset please? 😊
@DotNetCookbook
@DotNetCookbook Ай бұрын
What's the point of testing `Contains` performance against an array and not against a hashset?
@nickchapsas
@nickchapsas Ай бұрын
They are both converted in a span and performance is identical between an array and a hashset including ignore case cases.
@zachemny
@zachemny Ай бұрын
@@nickchapsas Are you saying that array and hashset both have identical performance characteristics and are basically the same data type?
@DotNetCookbook
@DotNetCookbook Ай бұрын
​@@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 Ай бұрын
@@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.
@_iPilot
@_iPilot Ай бұрын
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.
@moleee2
@moleee2 Ай бұрын
please make a video about micrsoft garnet
@LogicException
@LogicException Ай бұрын
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.
@Aaron31056
@Aaron31056 Ай бұрын
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.
@garcipat
@garcipat Ай бұрын
Is this already efficient if you only have one string?
@BearJewOo
@BearJewOo Ай бұрын
HashSet?
@vborovikov
@vborovikov Ай бұрын
the main limitation is that it doesn't work with Span
@nickchapsas
@nickchapsas Ай бұрын
Same performance but different data structure characteristics
@alirezanet
@alirezanet Ай бұрын
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 Ай бұрын
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 Ай бұрын
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
@Foxsterdota
@Foxsterdota Ай бұрын
6:02 random collection of words you say… hmm… 🤔😂
@urbanelemental3308
@urbanelemental3308 Ай бұрын
How does it compare against a hashset?
@nickchapsas
@nickchapsas Ай бұрын
They have identical performance
@polzaoops90
@polzaoops90 Ай бұрын
I just dont understand the different of the searchValue with the HashSet
@ThekillingGoku
@ThekillingGoku Ай бұрын
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.
@talwald1680
@talwald1680 Ай бұрын
Does this cost on startup?
@nickchapsas
@nickchapsas Ай бұрын
Yeah that’s where the overhead is
@thimok22
@thimok22 Ай бұрын
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 Ай бұрын
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 Ай бұрын
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 Ай бұрын
​@@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).
@Invudeal
@Invudeal Ай бұрын
What with Hashset?
@nickchapsas
@nickchapsas Ай бұрын
Same perf
@kinsondigital
@kinsondigital Ай бұрын
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 Ай бұрын
I know that ID too well lmao
@nickchapsas
@nickchapsas Ай бұрын
HAHAHHAAHAHHAHAHA
@SirBenJamin_
@SirBenJamin_ Ай бұрын
Earlier video : Dont micro optimize! This video : This is 6 nano seconds faster! 😄😄👍
@nickchapsas
@nickchapsas Ай бұрын
This actually scales insanely well so you can save micro to milliseconds depending on the size of the collection
@DanGolick
@DanGolick Ай бұрын
Add a benchmark using dictionary and set to store the values and test contains on them
@utubekade
@utubekade Ай бұрын
yeah was expecting to see that one in the benchmarks.
@99MrX99
@99MrX99 Ай бұрын
HashSet I think would make more sense for this comparison
@metaltyphoon
@metaltyphoon Ай бұрын
For smaller sizes arrays will always be faster
@nunyabuziness2700
@nunyabuziness2700 Ай бұрын
FURST!!!!
Await Async Tasks Are Getting Awesome in .NET 9!
9:24
Nick Chapsas
Рет қаралды 82 М.
Getting Started with Event Sourcing in .NET
37:07
Nick Chapsas
Рет қаралды 23 М.
I PEELED OFF THE CARDBOARD WATERMELON!#asmr
00:56
HAYATAKU はやたく
Рет қаралды 35 МЛН
Can You Draw The PERFECT Circle?
00:57
Stokes Twins
Рет қаралды 73 МЛН
ISSEI funny story😂😂😂Strange World | Pink with inoCat
00:36
ISSEI / いっせい
Рет қаралды 31 МЛН
Kitten has a slime in her diaper?! 🙀 #cat #kitten #cute
00:28
"Stop Using Singletons in .NET!" | Code Cop #009
13:52
Nick Chapsas
Рет қаралды 74 М.
The fastest way to iterate a List in C# is NOT what you think
13:42
Nick Chapsas
Рет қаралды 154 М.
The New Best Way To Search for Values in .NET 8
11:05
Nick Chapsas
Рет қаралды 68 М.
Make Your LINQ Up to 10x Faster!
11:08
Nick Chapsas
Рет қаралды 52 М.
Don't throw exceptions in C#. Do this instead
18:13
Nick Chapsas
Рет қаралды 247 М.
Why Developers Already Hate .NET 9
10:12
Nick Chapsas
Рет қаралды 70 М.
"Stop Wasting Memory on Strings in C#!" | Code Cop #016
9:20
Nick Chapsas
Рет қаралды 66 М.
What Is .NET Aspire? The Insane Future of .NET!
18:35
Nick Chapsas
Рет қаралды 255 М.
I PEELED OFF THE CARDBOARD WATERMELON!#asmr
00:56
HAYATAKU はやたく
Рет қаралды 35 МЛН