-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Performance improvement] Minimize number of properties placed in the runtimeconfig.json file #112956
Comments
Dropping these from runtimeconfig.json would be an observable change (these will no longer show up with One could argue that these text strings are our internal implementation details and nobody should be querying for them. I tried to make such argument for a different but related optimization in #95948 (comment), and that basically set a precedent that we don't consider external users using these specific strings as undefined behavior. What's the purpose of runtimeconfig.json on mobile in general? Could this just be embedded into the host executable in the expected format on mobile? That way we don't even need to parse a json or convert strings. |
@MichalStrehovsky we embed the data on mobile and pass the strings to CoreCLR on initialization, and that's the actual issue - there are ~30 entries, which means 60 strings that need to be converted from UTF8 to Unicode and parsed (for values), and the conversion (with memory allocation, copying etc) costs us around 15% of the initialization time. Purpose of runtimeconfig.json is identical to desktop/server. With regards to trimmer - the way I understood what was said in the linked to discussion on Discord, trimmer would remove the settings only if the relevant code was actually linked out, thus the settings would become irrelevant, since code that accesses/reads/uses them is no longer there. This sounds like a reasonable approach to me. |
Trimming analysis would need to figure out that all calls to In the limit if I write following code: Console.WriteLine(AppContext.TryGetSwitch(Console.ReadLine(), out _); This code needs to behave the same way before/after trimming irrespective of what string I type on the keyboard (I can e.g. type We'd need to build a lot of new analysis capabilities to be able to do this. For example, it's common to wrap this API and the string becomes difficult to find (we don't have capabilities to do this right now):
How is "initialization time" defined for this? From the C |
@MichalStrehovsky there's no |
@MichalStrehovsky I optimized the process at some point by pre-converting all the strings to Unicode and modifying |
Mono way of dealing with runtimeconfig.json is described in this document. I'm not sure if we really need it for CoreCLR, but it might be a food for thought. The main motivation behind filing this issue here is to seek ways to optimize processing of those properties. For their names, processing entails encoding from UTF-8 to Unicode - Android can do it at application build time, thus eliminating the overhead completely. It requires modifications to the CoreCLR API (which was part of this PR but were rejected, for the moment) to accept Unicode ( For values, it would mean eliminating conversion from UTF-8 to Unicode for strings and accepting actual values for other types so that no parsing occurs. Set of value types could be limited to the basic signed integer, a boolean and, maybe, a basic floating point number - anything else would be passed as string. Even if all the above changes were implemented, elimination of properties set to their default values would still be very welcome - in the spirit of minimizing the amount of dynamic processing at run time, especially for something that doesn't need to be there (since it's set to the default value). Please treat this as a very high level overview, a wish list if you will :) |
When building the default
dotnet new android
runtime application, we can see that the followingruntimeconfig.json
file is generated:After a discussion on Discord, it appears that most of those options aren't needed and might not be checked at run time, because the relevant code could have been trimmed away by the trimmer.
Each of those options is passed to CoreCLR runtime at initialization and each of them (both the name and the value) needs to be converted from UTF-8 to Unicode, which means memory allocation and the actual conversion. If a property isn't used, it means the time processing the property and memory allocated for it are both wasted.
It would be very good if we were able to omit unnecessary properties/switches from the JSON file. This could be done in two ways, it appears:
The text was updated successfully, but these errors were encountered: