How reflection changes will make your apps faster in .NET 7

preview_player
Показать описание

Hello everybody I'm Nick and in this video I will show you the updates that reflection got in .NET 7 that make it perform up to 4 times faster in some scenarios.

Don't forget to comment, like and subscribe :)

Social Media:

#csharp #dotnet #reflection
Рекомендации по теме
Комментарии
Автор

Nice to see this getting a boost, it will definitely improve my micro-orm construction time, so I assume it will also improve all ORMS and mappers in general across the board too, which is NEAT

figloalds
Автор

Usually I stop videos from other authors when patreons list appear. But in this case - I wait all way throught the list to hear this magic "keep coding" ))))

MicroLosi
Автор

Your easter eggs are so good and so subtle! Love it 😀

jradplowman
Автор

Wow this is super helpful for one of my projects. It uses a lot of reflection with ctors and this is very exciting. Thanks for sharing!

kaiserbergin
Автор

Interesting.

I believe that Blazor uses Reflection pretty heavily.
I'm guilty of making my interfaces very modular - creating lots of small reusable components.
However, they say that you should try limit your use of Components because each time they are rendered, reflection is used under the hood to set the values of component parameters.

In theory, this should be very good news for me, and Blazor in general.

conbag
Автор

Working on a project that makes use of LINQ Expression. Although I do need to use reflection initially for caching purposes. This is quite a benefit.

nitrous
Автор

cool, really like the performance improvement bring in reflection and generic area!

williamliu
Автор

Thanks for the update and video. Very important improvement indeed. Many libraries use creating instances by type names. IMHO calling methods via reflection is maybe less frequently used.

nothingisreal
Автор

I'd like to see benchmarks on PropertyInfo reflection. I use that a LOT and it would be nice to speed that up

davidwilliss
Автор

Hey Nick! I appreciate all your youtube work. Can I ask something?
Can you please make a video or video series about all about authentication with database.
With and with your own authentication handler, cookies and jwt, with middleware and with your own middleware, what's claims, identity, principal, security context, roles, how we store these in database, how we receive principal from frontend, why they need call AddAuthentication and then call AddCookies for example. Why we need Identity, what's oauth, what's identity server, what's mfa, external providers and why all of this stuffs are different and what's is different in web api, blazor, mvc, and in all .net template. And how this get evolved.
It's very confused for me, and I think there's so many people that thinks confused about authentication as well.
Thanks!!!

mjuniorjr
Автор

I once had a 3rd party library of proprietary closed source code that had a memory corruption issue. The company refused to believe it a problem even when I sent them the decompiled code with the problem in it and pointed out the line that needed changing. I used reflection to get the field that had the problem and pin it so that it wasn't moved by the GC when unmanaged code had a pointer to it. That is the only case where I thought reflection of private members was necessary and warranted.

baracek
Автор

thanks for the great video! it's rare to change a private variable. there are a lot of cases when the dynamic keyword could substitute reflection. I wonder how will this compare with performance.

TonoNamnum
Автор

That will help to clean a lot of code that is using lambda expressions and il emit for performance reasons

shingok
Автор

Neeto, I just installed the Visual Studio preview to try out Maui and if this monster benefits of something it's reflection. Same for XAML in WPF oh lord I might just pick that one up again for funsies as well.

danielschmid
Автор

Interesting, but does that performance improvement also exist in AOT? IL emitting typically doesn't work in AOT.

I'm still waiting for the fast reflection (new APIs) to make it into the runtime (the issue was put on future roadmap, unfortunately).

protox
Автор

I'm working on a personal project that relies on reflection a lot, so any performance improvements are always welcome to me.

_Aarius_
Автор

I used to cached the object properties to make reflection run faster.

onyxgc
Автор

I happened to be working on something in this area just now and I'm curious how the performance of the emitted IL compares to cached delegate performance. The delegate approach is certainly much faster than calling the get method directly via reflection, if you're making enough invocations to account for the overhead of constructing the delegate.

To illustrate what I mean, calling these delegates achieves the same performance as calling a virtual method, which is significantly faster than calling Invoke directly on the MethodInfo (at least before .NET 7...)

var getterDelegateType = typeof(Func<, >).MakeGenericType(propertyOwnerType, propertyInfo.PropertyType);
var setterDelegateType = typeof(Action<, >).MakeGenericType(propertyOwnerType, propertyInfo.PropertyType);
var getterDelegate =
var setterDelegate =

dadcraft
Автор

my irc bot library uses a lot of reflection this is good news for me

alexgriffith
Автор

Hey Nick, did you have the chance to benchmark the built-in DI, with the latest preview? Does it benefit from those improvements?

lalibi