-
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
NuGetSdkResolver adds significant overhead to evaluation and should not be used #4025
Comments
ACK on the negative performance impact. However, taking the feature out at this point is an impossibility. Could we work together to figure out how to change the current design in a way to meet the perf requirements for VS? |
@davkean Do you have the repro steps for how this measurement is taken? It is very bizarre that the nuget sdk resolver would be any worse than the regular resolver in the restored state. |
Putting this in 16.1 based on discussion just now. The resolver is actually now in the nuget repo, but first we should check that it is not something msbuild is doing in calling the resolver that is taking the time. |
Loooking at the code, https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/Microsoft.Build.NuGetSdkResolver/NuGetSdkResolver.cs It really doesn't do much in the restored state. |
It was doing work, loading files off disk and parsing them if I remember correctly. I wish I could remember how I verified the overhead, I think I isolated in a single project and measured evaluation time. It was the overwhelming cause of the CoreFX evaluation time. |
I can repro this: Evaluation time for |
I will profile this simple repro. |
Some quick thoughts: It is spending the most time parsing global.json, which is sad because my global.json is 74 bytes. We should look at switching to the new corefx json reader. There's a sources version for netfx IIRC. This file is trivial, we don't need a fancy deserializer. That said, it will avoid doing this more than once per build across projects: But I suspect VS evaluations aren't retaining this context object between projects. Fixing that if possible will help non-NuGet sdk evaluation considerably too. Another major contributor is nuget loading its configuration files. I presume it needs to do this to answer the question of where a downloaded package is because values in the config can impact the answer to that. The parsing there can probably be improved as well. For both of these we can possibly cache things in static state. and check config timestamps. I did some trickery like that in the non-nuget resolver. |
You don't have to switch if that's a big short term cost. Just use the JSONReader directly (since the global.json schema is fixed). The corefx reader should be lower allocation regardless though... |
So it's mostly Jit time being measured there. 140ms of jitting newtonsoft.json. |
😮 wow |
Have to check if build at least reuses that jitting. I think it might if the version of nuget in the sdk matches the version used by nuget msbuild resolver. The location of the dll is different for full msbuild. |
This time matches almost identical to what I found in dotnet/sdk#1483. |
Nope, strike that, JSON.NET was way less than above. |
We could just NGEN the one that comes with VS. |
@davkean Different API used? This is a huge hammer to read global.json: https://github.com/NuGet/NuGet.Client/blob/b6cd1677ae2bd3b07f4cc23c2e8d408f784e8b05/src/NuGet.Core/Microsoft.Build.NuGetSdkResolver/GlobalJsonReader.cs#L66 |
Yep, just to grab a couple of strings from that file, hell I betcha regex would beat this hands down. |
Yeah, there's a ReadAllText + IndexOf before it to avoid the deserialization, and that's not even showing up. 😆 |
I'll study some more tomorrow. This is interesting, but doesn't fully explain seeing 200ms - 400ms per project. I'm seeing 200ms, of which 140ms is Jitting that would not have been happening N times for loading of full solution, right? Mind you above you said: "I think I isolated in a single project and measured evaluation time". Possible your 200ms - 400ms included jitting? |
When I was looking at traces for CoreFx, the resolver showing up as significant, enough to make me isolate this case and measure it by itself. Best way to measure this would be grab a real world use - such as the CoreFx solution I shared. |
Yep. Will do that. |
The remaining 60ms is still quite bad. Just wondering if the isolation process bloated it to 200ms. I will dig. |
Bear in mind that the cost in that solution load will be ballooned by the number of evaluations (we evaluate every single project and configuration because the solution is incomplete) but it should be accurate to the cost of the total evaluation. |
The parsed SDK versions from MSBuild caches the resolved path for a particular SDK so that should only happen once. But for each unique SDK, the NuGet settings are read. That could be improved. |
I have a proposal to avoid the network access on the UI thread. See the "NuGet SDK Resolver" section in this proposal: dotnet/designs#104 Basically we are going to update the MSBuild SDK resolver interface so that a resolver can return no resolved SDK paths without failing. A resolver will also be able to return items that should be added to the evaluation. We can leverage this to fix the issue where the NuGet resolver downloads files on the UI thread. In VS, the resolver should run in a mode that does not allow downloading SDKs. Rather, if it can't find the SDK locally, it should return success and include a |
@dsplaisted with the optional workload work getting in, is it now possible for project system to update to handle this differently? |
This has been unblocked since the new SDK resolver support went in to MSBuild. We would need to make changes to the NuGet SDK Resolver, and the project system would also need to make changes. It would be nice to do that for 5.0.200 / VS 16.9. |
This is another issue caused by it: https://developercommunity.visualstudio.com/t/VisualStudio-was-hang-when-open-the-wpf-/1429662. We have ~57 threads all blocked behind the NuGet resolver. |
This is another issue caused by this: https://developercommunity.visualstudio.com/t/vs-performance-issue-ide-hangs-when-changing-file/1643242. |
NuGet Epic to address perf issues in the NuGetSDKResolver: NuGet/Home#11441. Please feel free to reach out to @jeffkl directly. |
I'm looking at this issue, trying to break it down into units of work across the affected components. A couple of observations:
The work needed here:
I have played with prototyping a change to NGEN |
The resolver needs to communicate this information to Visual Studio. You could probably include it as data on an exception, but adding items seems cleaner to me. Also if you do it via items, then I don't think you need to do the work in MSBuild to aggregate the information about which packages need to be downloaded, as there will just be multiple items with the information from the different resolver invocations. |
True, I think in general it's uglier to rely on structured data attached to an exception. On the other hand, if the resolver fails in this way, conceptually there's no value in evaluating the project. Other than the items added via |
For evaluation time, The NuGetSdkResolver is extremely slow.
Based on investigation in CoreFX, I found:
I've looked at the original design, and it's built on a incorrect premise; that its performance impact will only affect the loading state of projects that use it. The image it shows where projects are being loaded in the background via Asynchronous Solution Load (ASL) was removed from the product in 15.5.
If a project opts into this resolver, it has the following effects:
When we designed SDK resolvers, it was explicitly called out that due to them being used during evaluation - that they must be extremely fast and must not hit the network. While this only hits the network on unrestored state, it still has a large negative impact on evaluation time when the package is already downloaded.
This is the entire reason that NuGet restore does not run during the build while inside Visual Studio.
Rogue resolvers can cause Visual Studio and other IDEs to be blamed for performance and UI delay issues, please remove or change the design of this resolver to play nicely with Visual Studio.
The text was updated successfully, but these errors were encountered: