Memory usage improvements in build (#2626)

* Use a WorkspaceContext in dotnet-build to cache project data across
multiple compilations in a single build action
* Dramatically reduce string and object duplication by introducing a
"Symbol Table" that shares instances of NuGetVersion, NuGetFramework,
VersionRange and string across multiple lock-file parses

Test Results:
* Testing was done by compiling Microsoft.AspNetCore.Mvc (and it's
dependencies) and taking memory snapshots after each compilation in
dotMemory
* We used to allocate ~3MB and deallocate ~2.5MB on EACH compilation in
a single build action. This has been reduced to ~120KB
allocated/deallocated
* After introducing WorkspaceContext, total memory usage spiked from 6MB
across the whole build action to about 13MB, introducing the symbol
table dropped it back to about 5-6MB.
This commit is contained in:
Andrew Stanton-Nurse 2016-04-22 15:01:56 -07:00
parent 80df3688b1
commit ef0ca39da1
42 changed files with 496 additions and 268 deletions

View file

@ -109,12 +109,11 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
private CommandResult RunProcess(string executable, string args, StreamForwarder stdOut, StreamForwarder stdErr)
{
CurrentProcess = StartProcess(executable, args);
var threadOut = stdOut.BeginRead(CurrentProcess.StandardOutput);
var threadErr = stdErr.BeginRead(CurrentProcess.StandardError);
var taskOut = stdOut.BeginRead(CurrentProcess.StandardOutput);
var taskErr = stdErr.BeginRead(CurrentProcess.StandardError);
CurrentProcess.WaitForExit();
threadOut.Join();
threadErr.Join();
Task.WaitAll(taskOut, taskErr);
var result = new CommandResult(
CurrentProcess.StartInfo,
@ -128,14 +127,13 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
private Task<CommandResult> RunProcessAsync(string executable, string args, StreamForwarder stdOut, StreamForwarder stdErr)
{
CurrentProcess = StartProcess(executable, args);
var threadOut = stdOut.BeginRead(CurrentProcess.StandardOutput);
var threadErr = stdErr.BeginRead(CurrentProcess.StandardError);
var taskOut = stdOut.BeginRead(CurrentProcess.StandardOutput);
var taskErr = stdErr.BeginRead(CurrentProcess.StandardError);
var tcs = new TaskCompletionSource<CommandResult>();
CurrentProcess.Exited += (sender, arg) =>
{
threadOut.Join();
threadErr.Join();
Task.WaitAll(taskOut, taskErr);
var result = new CommandResult(
CurrentProcess.StartInfo,
CurrentProcess.ExitCode,