Тёмный

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

NDC Conferences
Подписаться 199 тыс.
Просмотров 22 тыс.
50% 1

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...
ndcoslo.com/

Опубликовано:

 

14 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 34   
@spottedmahn
@spottedmahn Год назад
“Practical learner” been there many a times; you’re not alone!
@daniel.marbach
@daniel.marbach Год назад
Thank you ❤
@AlexanderBelikov
@AlexanderBelikov 5 месяцев назад
Great presentation, thank you!
@daniel.marbach
@daniel.marbach 3 месяца назад
Thank you!
@lizard450
@lizard450 6 месяцев назад
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.
@norm6096
@norm6096 Год назад
Awesome presentation. 🙂 Thanks alot!
@daniel.marbach
@daniel.marbach Год назад
Thank you for leaving your feedback!
Год назад
Great talk. Great presentation.
@daniel.marbach
@daniel.marbach Год назад
Thanks for the feedback 🎉
@oguzhanK1234
@oguzhanK1234 Год назад
I really like how C# evolves into Typescript and TS evolces into C# :D
@daniel.marbach
@daniel.marbach Год назад
Haha. You are not wrong 😂
@Sp1tfire100
@Sp1tfire100 7 месяцев назад
They both are created by the same guy - Anders Hejsberg
@ilia__k
@ilia__k Год назад
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 Год назад
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
@daniel.marbach
@daniel.marbach Год назад
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!
@michakonarski8203
@michakonarski8203 Год назад
Great presentation.
@daniel.marbach
@daniel.marbach Год назад
Thank you for taking the time to make this comment!
@unexpectedkAs
@unexpectedkAs Год назад
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 :)
@daniel.marbach
@daniel.marbach Год назад
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.
@Crossbow123
@Crossbow123 11 месяцев назад
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?
@daniel.marbach
@daniel.marbach 10 месяцев назад
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.
@pkamp20
@pkamp20 Год назад
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 😀
@daniel.marbach
@daniel.marbach 10 месяцев назад
Yep 😂 and I have implemented my own pooling mechanisms before on top of dictionaries with locks and later on concurrent dictionaries. Good memories
@DragonRaider5
@DragonRaider5 Год назад
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 Год назад
However high performance still is very important, as less servers can make a significant impact on the environmental impact of your application.
@marloelefant7500
@marloelefant7500 Год назад
Using less resources can also be economically sensible, especially when your hardware is fairly expensive, like GPUs.
@ndchunter5516
@ndchunter5516 Год назад
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 Год назад
@@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 Год назад
This is the very bad philosophy. All resources are scarce. Please write efficient code always!
@livingdeathD
@livingdeathD 6 месяцев назад
why this is a video? 😍😍😍😍😍😍
Далее
다리찢기 고인물⁉️😱 Leg Splits Challenge
00:37
Common mistakes in EF Core - Jernej Kavka - NDC Oslo 2023
1:03:43
What Makes A Great Software Engineer?  -  Alexis Agahi
20:15
The Fastest Way to Modify a List in C# | Coding Demo
10:30
The weirdest way to loop in C# is also the fastest
12:55
Premature Optimization
12:39
Просмотров 819 тыс.