Publish Performace
Steps to reproduce
Take a project with a high number of dependencies declared. Both project and package ones. dotnet publish the project
Expected behavior
dotnet publish should return in a reasonable period of time.
Actual behavior
In my project it is taking 50 minutes to do the publish. This is a portable application so it really has nothing more to do that copy pre-compiled assemblies to the output folder
This is the same on Linux or Windows.
Related Issues
dotnet/sdk#6080
Possible Resolution
I diagnosed as much as possible what was causing the problem. The time is being taken in the CollectNonBuildDependencies in ProjectModelPlatformExtensions. This code appears to recurse through all dependencies to build its list of exclusions. I applied a simple optimization as below which prevented it from re-checking those already located. This resulted in an almost instantaneous return although not completely tested preventing expensive recursive traversal of the dependency graph would be beneficial.
https://github.com/dotnet/cli/blob/rel/1.0.0/src/Microsoft.DotNet.ProjectModel/ProjectModelPlatformExtensions.cs
The addition of the if (!acceptedExports.Contains(export.Library.Identity.Name)) { } block below prevents the performance hit. Hopefully it doesn't change the functionality ??
private static void CollectNonBuildDependencies(IDictionary<string, LibraryExport> exports, IEnumerable<LibraryRange> dependencies, HashSet<string> acceptedExports)
{
foreach (var dependency in dependencies)
{
var export = exports[dependency.Name];
if (!dependency.Type.Equals(LibraryDependencyType.Build))
{
if (!acceptedExports.Contains(export.Library.Identity.Name))
{
acceptedExports.Add(export.Library.Identity.Name);
CollectNonBuildDependencies(exports, export.Library.Dependencies, acceptedExports);
}
}
}
}
Environment data
.NET Command Line Tools (1.0.0-preview2-003121)
Product Information: Version: 1.0.0-preview2-003121 Commit SHA-1 hash: 1e9d529bc5
Runtime Environment: OS Name: Windows OS Version: 6.1.7601 OS Platform: Windows RID: win7-x64
I've also debugged to the same point when trying to build our 54 project solution (don't ask!) - it takes around an hour to build on Windows, and at least 3 hours on Arch Linux (I cancelled it as it was taking way too long). I have noticed that if I change our solution's entry point project to target net452 instead of netcoreapp1.0 the build time goes down to around 30 seconds, which I can only assume is how long it's meant to take.
If this change has no side effects, getting it merged would be brilliant for us as we can finally start using .NET Core for our product!
I ended up creating a dotnet-jpublish (j being my initial) tool with the above changes in it. It will not do the auto-build step (as that is an internal call) but otherwise it seems to work. @jonjo-manywho : If you would like a copy of that until a fix is in place then I'll publish the project for you.
[FYI : I have to target netcoreapp1.0 as my platform in Linux]
@jamesgibbs100 yes please, that would be handy to try building a netcoreapp1.0 version! We also want to target Linux so net452 wouldn't work for us, it only finishes the build in a reasonable amount of time when targeting it.
@jonjo-manywho Please find repo here : dotnet-jpublish
- You will need to include it in your nuget feeds obviously
- Then add a "tools" entry for it in the project.json you want use it in.
- Then
dotnet buildfollowed bydotnet jpublishfrom the within the project directory
Please note : I have only tried this on portable apps, not standalone ones
@jamesgibbs100 neat, thanks - I'll give it a try with our solution.
Any acknowledgement from the development team on this issue? @jamesgibbs100's fix works for us, but until it's supported in the official CLI, we're totally blocked on running under .NET Core. Maybe a pull request from @jamesgibbs100 will push this fix along?
@jonjo-manywho : An acknowledgement would be very good. It might be that the team is moving to MSBUILD/CSPROJ for the next release and that this problem goes away ??
Can someone share a repro project? 20-50 mins is absolutely unreasonable. We need to address that.
With a repro project I will:
dotnet migratefrom the solution root [with 1.0.0-preview3-004056 or later installed]dotnet restorethe head project [please identify]dotnet publishand see how long it takes.- IF it still takes a long time,
dotnet publish /v:diagto see where the time is being spent
I list the steps in case anyone wants to try it on their own projects :)
It would be great to know if this is still an issue both in the 1.0 SDK that is now release or the 2.0 SDK that is in beta.
I think its cleared up now. I have stopped using the hack above and builds are ok now. I'm on 1.1.1
Yep, this seems to have cleared up for us too
Thanks for confirming. Closing...