-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Update plugin assembly loading for .NET 3/5 #5037
Comments
Note: this was already mostly done in 90ac0c3. We could mostly pull back to that, but we'll need to keep the escape hatches and other behaviors of the current implementation. |
Please to take a look at the unique requirements proposed by #1755 which was recently duped against this one. The goal being that now that msbuild isn't a Windows, .NET Framework only process, we need a more scalable, simpler model for plugins to ship without shipping the full transitive closure of their own runtime dependencies for every single OS+runtime, while still being able to run on each of these. |
@AArnott are you saying there are MSBuild-specific requirements that are not covered by |
@rainersigwald I'm not sure. I don't see anything in the |
@rainersigwald Are there examples how to plugin with this in view? Thank you... |
Hi @rainersigwald, I've recently come across a memory leak caused by the fact that assemblies are loaded into According to my tests, it is actually quite an easy fix. It is enough to construct the Documentation says that it is pretty safe, as the assembly will be unloaded only if it is no longer referenced/used (https://docs.microsoft.com/en-us/dotnet/standard/assembly/unloadability). I wonder whether you see any problems with making ALC collectible? Would you accept a PR for it? |
@marcin-krystianc We considered making the ALCs collectible, but that can harm performance in some cases--specifically, when we're reusing MSBuild nodes for a subsequent build, having the tasks loaded (and JITted) from a previous run can speed up the dev inner loop. I'm a bit confused by the leak you're describing, though. Some questions:
|
Ad 1
Ad 2 Here is simplified version of our code in which we create an
Ad 3 |
@marcin-krystianc Ah, thank you for the details! That should be resolvable; I filed #6842. |
We want to use static for CoreClrAssemblyLoader so each unique SDK resolver assembly is loaded into memory and JITted only once. Fixes #6842 (comment) ### Context We use static for the `CoreClrAssemblyLoader` field so each unique SDK resolver assembly is loaded into memory and JITted only once. All subsequent load requests will return assembly from the assembly loader's cache instead of loading it again from disk. This change increases the performance of SDK resolution and at the same time avoids leaking memory due to loading the same SDK resolver assembly multiple times and never unloading it. ### Changes Made The `CoreClrAssemblyLoader` field in the `SdkResolverLoader` class was changed from non-static to static member. The same instance of `CoreClrAssemblyLoader` will be used by all instances of `SdkResolverLoader`. It is consistent now with other uses of `CoreClrAssemblyLoader` in msbuild. ### Testing Tested manually using repro from #5037 (comment) ### Notes Alternative approach would be to use collectible `CoreClrAssemblyLoader` / `AssemblyLoadContext` - that would fix the leak as well but it would be less performant as it wouldn't benefit from re-using already loaded and JITed assemblies.
Fixes #4081 and Fixes #1887; progress towards #5037 Context MSBuild doesn't currently respect .deps.json files for plugins (tasks). This can lead to incorrect versions of assemblies being found as finding the AnyCPU version of an assembly instead of the windows-specific version. Changes Made Use AssemblyDependencyResolver as a second pass (after looking for "well-known assemblies") to automatically use the deps.json file to find the right assembly. Testing Verified that for a task assembly with a rid-specific dependency, it finds the rid-specific dependency as specified by the deps.json file. Also verified that it can find native assemblies and that the issue that inspired this (dotnet/sdk#23498) no longer reproduces after giving nuget a .deps.json file specifying the correct version.
…ler, since MSBuild isn't going to let us do it correctly, currently. Held up on dotnet/msbuild#5037
@rainersigwald, is this issue still relevant? All linked PRs in original post were merged. |
I don't think we rigorously did
But yes, I think we can close. |
Several improvements to #4916 are possible once we're moved to target .NET 3+:
AssemblyDependencyResolver
to make native dependencies easier to handle (Load plugins in an AssemblyLoadContext #4916 (comment))Resolving
rather thanLoad
(https://github.com/microsoft/msbuild/pull/4916/files/6d4c3b1e2adcd6ce97233b85489c514b2b990949#r363710290, Load plugins in an AssemblyLoadContext #4916 (comment))The text was updated successfully, but these errors were encountered: