Don't retain host probing-path properties in CLR config and AppContext#129995
Open
elinor-fung wants to merge 5 commits into
Open
Don't retain host probing-path properties in CLR config and AppContext#129995elinor-fung wants to merge 5 commits into
elinor-fung wants to merge 5 commits into
Conversation
In coreclr_initialize, the wide-string copies of all host properties were stored in the CLR config knobs and held forever. For probing-path properties (TRUSTED_PLATFORM_ASSEMBLIES, NATIVE_DLL_SEARCH_DIRECTORIES, PLATFORM_RESOURCE_ROOTS, APP_PATHS) these duplicate data the runtime already owns: the binder/AppDomain parses them into its own structures during CreateAppDomainWithManager, and the managed AppContext.Setup copies each value into a managed string. The TPA list in particular can be tens of KB. Build a filtered property array for Configuration::InitializeConfigurationKnobs that excludes those four properties, and free their wide-string copies after CreateAppDomainWithManager has consumed them. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Extend the host-property elision so the probing-path properties (TRUSTED_PLATFORM_ASSEMBLIES, NATIVE_DLL_SEARCH_DIRECTORIES, PLATFORM_RESOURCE_ROOTS, APP_PATHS) are not stored in managed AppContext.s_dataStore either. The runtime already owns the parsed forms (binder's TPA map, AppDomain's native search dirs, etc.), so the managed string copy is redundant. AppContext.GetData transparently reconstructs the value on first access via a new QCall (AppContext_TryGetHostPropertyValue) and caches the result for subsequent calls. The QCall returns TRUE when the property has data in the binder/AppDomain state, FALSE otherwise - GetData returns null in the latter case, matching the previous behavior of returning null for properties the host did not pass. The Mono and NativeAOT code paths are unchanged. Saves the managed string allocation for each of these properties (~26 KB for TPA in a typical framework). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Verify that AppContext.GetData can retrieve the four known host probing-path properties (TRUSTED_PLATFORM_ASSEMBLIES, NATIVE_DLL_SEARCH_DIRECTORIES, PLATFORM_RESOURCE_ROOTS, APP_PATHS) which are reconstructed on demand from binder/AppDomain state rather than stored in AppContext.s_dataStore. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @agocke |
Contributor
There was a problem hiding this comment.
Pull request overview
Reduces retained memory for large host-provided probing path properties by no longer storing them permanently in CLR config knobs or AppContext’s managed data store, instead reconstructing them on demand from binder/AppDomain state.
Changes:
- Stop storing known host probing-path properties in
AppContext.Setup, and lazily reconstruct them onAppContext.GetDatavia a new QCall. - Filter out host probing-path properties when initializing CLR configuration knobs, and free the excluded wide-string copies after AppDomain creation.
- Add/adjust HostActivation tests to validate
AppContext.GetDataaccess for known host properties.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/AppContext.cs | Skips storing known host probing-path properties at setup; lazily retrieves and caches them when requested via GetData. |
| src/coreclr/System.Private.CoreLib/src/System/AppContext.CoreCLR.cs | Adds host-property identification and a QCall import used to reconstruct values on demand. |
| src/coreclr/vm/qcallentrypoints.cpp | Registers the new QCall entrypoint. |
| src/coreclr/vm/appdomainnative.hpp | Declares the new QCall entrypoint signature. |
| src/coreclr/vm/appdomainnative.cpp | Implements QCall to reconstruct host property values from binder/AppDomain state. |
| src/coreclr/dlls/mscoree/exports.cpp | Filters known host probing-path properties out of CLR config knob storage and frees excluded wide-string copies post-AppDomain creation. |
| src/installer/tests/HostActivation.Tests/RuntimeProperties.cs | Updates assertions and adds coverage for retrieving known host properties via AppContext.GetData. |
Copilot's findings
- Files reviewed: 7/7 changed files
- Comments generated: 1
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four well-known host probing-path properties —
TRUSTED_PLATFORM_ASSEMBLIES,NATIVE_DLL_SEARCH_DIRECTORIES,PLATFORM_RESOURCE_ROOTS, andAPP_PATHS— are computed by the host and then, inside the runtime, copied and retained multiple times: wide-string copies in the CLR config knobs, managed strings inAppContext's data store, and the parsed binder/AppDomain structures the runtime actually uses. The config-knob andAppContextcopies just duplicate data the runtime already owns in parsed form. The TPA list is the largest of these and grows as the app takes dependencies on other libraries or frameworks.This change stops keeping the copies in the config knobs and managed
AppContext. The host properties are still handed to the runtime and parsed by the binder and AppDomain, but the config knob copies for these four properties are dropped and they are no longer stored on theAppContextat startup. When one of these properties is requested throughAppContext.GetData, the value is reconstructed from the binder/AppDomain state via a new QCall and stored for subsequent reads. Reconstruction is not byte-for-byte: the TPA list comes back deduplicated by simple name and in a different order, and a property the host passed as empty reads back asnullrather than an empty string.cc @dotnet/appmodel @AaronRobinsonMSFT
Note
Portions of this PR description were drafted with the assistance of GitHub Copilot.