-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Remove unnecessary indirect use of managed wcslen from AppContext setup #101318
Conversation
Pinging stephen since github suggested him. I'd love to get your thoughts or thoughts from one of Dictionary's other maintainers on the right way to perform this startup optimization without lowering our code quality. I tried a few things before arriving at this current solution. |
src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs
Outdated
Show resolved
Hide resolved
How many methods execute in a typical Blazor app before network or background operations start? |
I don't have a way to measure that right now, I'm still working on getting a blazor app to start with a modified runtime build. For a simple blazor-less mono-wasm application, before I started working on this we were looking at around 850 different methods having code generated, and it's around 710 with my current fix set, and I have a theory for how to prune another 50 or so from that by making static constructors cheaper. From what I've seen in profiles of aot'd blazor my guess is it's probably in the neighborhood of 5000 methods or more. The question is whether we can move enough stuff later in startup for apps to realistically kick off network traffic, I'll have a better sense of that once I get blazor working with my local runtime binaries so I can get dense logs of method compile order. The impact of this class of optimization is probably much smaller for AOT startup. |
5fb43c4
to
ec93425
Compare
Should I change this in coreclr too? It looks like corhost.cpp calls this Setup method as well. |
ab96e68
to
0844d15
Compare
I do not think that the managed For CoreCLR, I would pass the UTF8 key/value pairs to the managed side directly to create the managed strings without creating the intermediate copies. It would require more significant refactoring. |
OK, if it's already there then we aren't improving things by allowing it to be trimmed. Thanks for the context. |
Remove unnecessary use of EqualityComparer.Default from AppContext setup
…and EqualityComparer.Default when creating a dictionary with string keys
a3391e6
to
1ea8882
Compare
…ext setup (dotnet#101318) Remove unnecessary indirect use of managed wcslen from AppContext setup since it pulls in vector dependencies and we already know the length of each string
…ext setup (dotnet#101318) Remove unnecessary indirect use of managed wcslen from AppContext setup since it pulls in vector dependencies and we already know the length of each string
At least on mono, during AppContext setup we use the
string::.ctor(char*)
constructor, which calls a managed, vectorized implementation ofwcslen
- this pulls in a bunch of vector code to optimize a codepath that is cold:We also use the default comparer when creating an instance ofDictionary<string, object>
, which pulls inGenericEqualityComparer
andNonRandomizedStringEqualityComparer
stuff we don't need when we could just use anOrdinalComparer
directly:We already compute the length of the appcontext arguments when converting them to UTF-16, at least in mono, so this PR switches to a 5-argument variant of Setup that accepts an array of lengths, so it can use a simpler/faster string constructor overload.
A lot of this code may get pulled in later by user code or library code in i.e. Blazor, but this ideally lets us get much further into app startup before that happens, at which point important network requests or background operations may have started instead of being blocked on the creation of AppContext.