✅ Use() Extension Overload

I'm working with the Use method in ASP.NET Core and have encountered two overloads. The first, taking HttpContext and RequestDelegate, is clear to me. However, I'm struggling to understand the second overload where the use lambda accepts HttpContext and Func<Task>. Some articles mention that this approach leads to additional allocations per request. Could someone elaborate on what these extra allocations are and how they impact performance?
6 Replies
viceroypenguin
viceroypenguin5mo ago
The extra allocations are due to how a Func<> is created dynamically. Extra allocations means more work allocating the object and for the GC later. That said, the difference is negligible for most applications. Use whichever is easiest for you and don't worry about perf issues until you have identified that there is one.
steven preadly
steven preadlyOP5mo ago
what dose this means perf
viceroypenguin
viceroypenguin5mo ago
short-hand for "performance"
steven preadly
steven preadlyOP5mo ago
this are memory stuff and GC
viceroypenguin
viceroypenguin5mo ago
yes. and again, you really shouldn't need to worry about it for most applications. get something working first, then if you identify a performance issue, address it at that time.
steven preadly
steven preadlyOP5mo ago
any ways the recommended by the docs is to use the one that takes the HttpContext and a RequestDelegate , and thank you
Want results from more Discord servers?
Add your server