Performance tricks I learned from contributing to open source .NET packages - Daniel Marbach

  Рет қаралды 20,439

NDC Conferences

NDC Conferences

11 ай бұрын

NDC Oslo 2023
As a practical learner, I've found performance optimizations are my biggest challenge and where I've learned the most helpful tricks, mostly by trial and error. It turns out the Azure .NET SDK is a perfect “playground” for learning those tricks-it's maintained by people who care and give feedback.
Over the past few years, I've contributed over seventy pull requests to the Azure .NET SDK. In this session, I'll walk you through the performance improvements I made, and help you develop your own “superpowers”-spotting and avoiding closure allocations, finding opportunities for memory pooling, and more.
Check out our new channel:
NDC Clips:
@ndcclips
Check out more of our featured speakers and talks at
ndcconferences.com/
ndcoslo.com/

Пікірлер: 33
@AlexanderBelikov
@AlexanderBelikov 18 күн бұрын
Great presentation, thank you!
@lizard450
@lizard450 Ай бұрын
For the completeinternalasync you are basically making a firstordefault operation with the foreach. A regular old for loop is usually faster than a foreach. Both options are worth testing. You'd likely get a better performance gain by using a concurrent dictionary as a concurrent hashset than the concurrent bag.
@spottedmahn
@spottedmahn 11 ай бұрын
“Practical learner” been there many a times; you’re not alone!
@marbachdaniel
@marbachdaniel 11 ай бұрын
Thank you ❤
@norm6096
@norm6096 11 ай бұрын
Awesome presentation. 🙂 Thanks alot!
@marbachdaniel
@marbachdaniel 11 ай бұрын
Thank you for leaving your feedback!
@oguzhan0Kahyaoglu
@oguzhan0Kahyaoglu 10 ай бұрын
I really like how C# evolves into Typescript and TS evolces into C# :D
@marbachdaniel
@marbachdaniel 10 ай бұрын
Haha. You are not wrong 😂
@Sp1tfire100
@Sp1tfire100 3 ай бұрын
They both are created by the same guy - Anders Hejsberg
11 ай бұрын
Great talk. Great presentation.
@marbachdaniel
@marbachdaniel 11 ай бұрын
Thanks for the feedback 🎉
@michakonarski8203
@michakonarski8203 8 ай бұрын
Great presentation.
@marbachdaniel
@marbachdaniel 8 ай бұрын
Thank you for taking the time to make this comment!
@unexpectedkAs
@unexpectedkAs 10 ай бұрын
Super interesting! Knew some, learned some. Something I am missing are comments. Comments that will tell other / future devs why a foreach is used instead of a LINQ, or why the "manual" memory manipulation. Do you include those benchmarks in your code base as a justification / documentation? Or maybe in your unit tests? Because you also want to prevent someone undoing something just because they think the code is too complicated. Also, maybe you could sepak about how do you weight performance vs less-intuitive code? You also mention that you analized the error caees of a method and decised a try was not necessary. Understanding how did you precisely evaluate that can help a lot! Thanks for the talk :)
@marbachdaniel
@marbachdaniel 10 ай бұрын
Thanks for the feedback! I do agree, comments are a necessary and helpful way to indicate to peers or ourselves in the future why a code has been written in a certain way. Another tool I use is to document some additional context in the pull request description and in a design decision record. I would have loved to include even more content (which I have in the repository I linked in the talk, but 60min is the timeslot I had :) ) When it comes to the benchmarks and where to put them, this depends on the performance culture that you have already incorporated. I have a talk upcoming that goes into that ;) Long story short is that I have used multiple approaches with pros and cons. Placing the benchmarks into a dedicated repository, adding them alongside the code into the same repository or just adding it as snippets to the pull requests I have done to third-party repositories. For regression testing, the more important question is probably though the infrastructure you use to get reliable results (hint for example github action runners are not a good runtime environment) and how to make them comparable.
@ilia__k
@ilia__k 11 ай бұрын
Some of the Linq suggestion are already outdated, modern Linq heavily relies on `IIListProvider` (not a typo), that optimizes all 1-to-1 operation over collections. E. g., `myArray.Select(x => x).TryGetNonEnumeratedCount()` will be true because Select is aware that its source is a fixed size collection. This applies to methods like `.ToArray()` or `.ToList()`
@weriohjiuhuih
@weriohjiuhuih 11 ай бұрын
It is still relevant actually This is the IL code generated in .NET 6 for the given code in the slide: IL_002a: ldsfld class [System.Runtime]System.Func`2 C/'c'::'9__2_1' IL_002f: dup IL_0030: brtrue.s IL_0049 IL_0032: pop IL_0033: ldsfld class C/'c' C/'c'::'9' IL_0038: ldftn instance bool C/'c'::'b__2_1'(valuetype [System.Runtime]System.Guid) IL_003e: newobj instance void class [System.Runtime]System.Func`2::.ctor(object, native int) IL_0043: dup IL_0044: stsfld class [System.Runtime]System.Func`2 C/'c'::'9__2_1' IL_0049: call bool [System.Linq]System.Linq.Enumerable::Any(class [System.Runtime]System.Collections.Generic.IEnumerable`1, class [System.Runtime]System.Func`2) IL_004e: brfalse.s IL_0060 As you can see at IL_003e it still allocates new func
@marbachdaniel
@marbachdaniel 11 ай бұрын
That's a fair comment. I think I mentioned during the talk that some of the optimizations will no longer be relevant over time because LINQ gets more and more optimized with newer versions of the runtime/bcl. Yet many of the practices are still relevant to think about on the hot path when dealing with collections. Thanks for the feedback!
@livingdeathD
@livingdeathD Ай бұрын
why this is a video? 😍😍😍😍😍😍
@Crossbow123
@Crossbow123 6 ай бұрын
It's great to see that there is at least some return on investment. But I honstly do not understand why someone would work for a big corporation without any financial reward considering that this corporation is turning each and every contribution to Azure into money. I mean its one thing to contribute to common technologies like .NET itself that's freely available. But Azure?
@marbachdaniel
@marbachdaniel 5 ай бұрын
To be fair I contributed to the Azure NET SDK which is freely available according to your definition. But yes eventually you have to pay for the services. For me it was really about doing learning on a real world and big code base to turn my learnings into some impactful that expands my learning.
@DragonRaider5
@DragonRaider5 11 ай бұрын
The existance of systems working on a large scale doesnt imply high performance. If you build an application which can scale horizontally without much issue and isnt limited by shared resources, it doesnt matter if a single server makes 1k RPS or 2k RPS as long as you have the money to pay for the resources.
@DragonRaider5
@DragonRaider5 11 ай бұрын
However high performance still is very important, as less servers can make a significant impact on the environmental impact of your application.
@marloelefant7500
@marloelefant7500 11 ай бұрын
Using less resources can also be economically sensible, especially when your hardware is fairly expensive, like GPUs.
@ndchunter5516
@ndchunter5516 11 ай бұрын
utilizing this server fully is however rly important. if you process something and after that you transfer the result, you utilize cpu and network or storage bandwith in sequence. if you break it down to use both at the same time you still have the same workload but the user is already getting results while processing. also this broken down task allow for vertical scaling on a finer granularity
@DragonRaider5
@DragonRaider5 11 ай бұрын
@@ndchunter5516 we might be talking about different topics. I was reffering to the claims at the beginning of the video, which said that C# is a high performance language as proven by the fact that there are high workload services running on C# clusters.
@anm3037
@anm3037 11 ай бұрын
This is the very bad philosophy. All resources are scarce. Please write efficient code always!
@pkamp20
@pkamp20 7 ай бұрын
ArrayPool. That brings back memories of the embedded software I did 20 years ago. Used a memory pool of fixed size blocks, to prevent using malloc in 99% of the message cases. Always nice to see concepts of decades ago, still show up when needed 😀
@marbachdaniel
@marbachdaniel 5 ай бұрын
Yep 😂 and I have implemented my own pooling mechanisms before on top of dictionaries with locks and later on concurrent dictionaries. Good memories
CQRS pitfalls and patterns - Udi Dahan - NDC Oslo 2023
59:26
NDC Conferences
Рет қаралды 22 М.
Eccentric clown jack #short #angel #clown
00:33
Super Beauty team
Рет қаралды 24 МЛН
Do you have a friend like this? 🤣#shorts
00:12
dednahype
Рет қаралды 48 МЛН
Would you like a delicious big mooncake? #shorts#Mooncake #China #Chinesefood
00:30
The weirdest way to loop in C# is also the fastest
12:55
Nick Chapsas
Рет қаралды 247 М.
The Fastest Way to Modify a List in C# | Coding Demo
10:30
Zoran Horvat
Рет қаралды 19 М.
Stop Using the Worst Way to Loop Lists in .NET!
9:35
Nick Chapsas
Рет қаралды 43 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 752 М.
How To Get Started With Open Source
13:03
Web Dev Simplified
Рет қаралды 92 М.
3.5.A Solar Mobile 📱 Charger
0:39
Gaming zone
Рет қаралды 320 М.
How charged your battery?
0:14
V.A. show / Магика
Рет қаралды 2,9 МЛН
5 НЕЛЕГАЛЬНЫХ гаджетов, за которые вас посадят
0:59
Кибер Андерсон
Рет қаралды 889 М.
iPhone 12 socket cleaning #fixit
0:30
Tamar DB (mt)
Рет қаралды 7 МЛН