-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Read interface IList.Count once rather than per iteration #9962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 😻 |
src/Razor/Razor.Runtime/src/Runtime/TagHelpers/TagHelperRunner.cs
Outdated
Show resolved
Hide resolved
What's the number of calls after the changes? |
awesome! |
It's a shame that the simplest way to implement a collection type leads you down this path - thinking of https://github.com/aspnet/AspNetCore/blob/master/src/Razor/Razor/src/TagHelpers/ReadOnlyTagHelperAttributeList.cs and other types we have that subclass I've been thinking about how I want to implement https://github.com/aspnet/AspNetCore/blob/master/src/Http/Http.Abstractions/src/Routing/EndpointMetadataCollection.cs#L100 - because we need to change this in 3.0 to return something better than |
Thanks @benaadams |
Inspired by dotnet#9962, read .Count once rather than once per loop iteration.
…ellany (#11253) * Read interface IList.Count once rather than per iteration Inspired by #9962, read .Count once rather than once per loop iteration. * Use nameof() instead of ToString() Use constant nameof() on enum value, rather than runtime ToString(). * Right-size dictionary Initialize dictionary with a fixed number of elements to the number of elements it contains. * Use DisposeAsync() Use DisposeAsync() on FileBufferingReadStream in input formatters. * Override DisposeAsync() Override DisposeAsync() to call DisposeAsync() on the inner stream. * Use GetValueOrDefault() for content-length Use GetValueOrDefault() to read the content length once instead of checking HasValue once and Value up to three times. * Update Microsoft.AspNetCore.WebUtilities.netcoreapp3.0.cs Add DisposeAsync(). * Use DisposeAsync() Use DisposeAsync() on transcoding streams as other formatters do.
Cache
IList.Count
when used as an iteration condition as it is an uninlinable interface call so needs to be evaluated each time.30M calls for 44k requests to
dotnet new mvc
homepage; or ~680 calls per request./cc @rynowak