-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C#: Parallelize restore logic of missing packages #14243
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using Semmle.Util; | ||
|
@@ -19,23 +20,33 @@ public DotNetCliInvoker(ProgressMonitor progressMonitor, string exec) | |
this.Exec = exec; | ||
} | ||
|
||
private ProcessStartInfo MakeDotnetStartInfo(string args, bool redirectStandardOutput) | ||
private ProcessStartInfo MakeDotnetStartInfo(string args) | ||
{ | ||
var startInfo = new ProcessStartInfo(Exec, args) | ||
{ | ||
UseShellExecute = false, | ||
RedirectStandardOutput = redirectStandardOutput | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true | ||
}; | ||
// Set the .NET CLI language to English to avoid localized output. | ||
startInfo.EnvironmentVariables["DOTNET_CLI_UI_LANGUAGE"] = "en"; | ||
return startInfo; | ||
} | ||
|
||
private bool RunCommandAux(string args, bool redirectStandardOutput, out IList<string> output) | ||
private bool RunCommandAux(string args, out IList<string> output) | ||
{ | ||
progressMonitor.RunningProcess($"{Exec} {args}"); | ||
var pi = MakeDotnetStartInfo(args, redirectStandardOutput); | ||
var exitCode = pi.ReadOutput(out output); | ||
var pi = MakeDotnetStartInfo(args); | ||
var threadId = $"[{Environment.CurrentManagedThreadId:D3}]"; | ||
void onOut(string s) | ||
{ | ||
Console.Out.WriteLine($"{threadId} {s}"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Could be inlined as lambdas? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it could be. (I think in general local functions perform better than lambdas. But not in this case, because we're passing the local function as an |
||
} | ||
void onError(string s) | ||
{ | ||
Console.Error.WriteLine($"{threadId} {s}"); | ||
} | ||
var exitCode = pi.ReadOutput(out output, onOut, onError); | ||
if (exitCode != 0) | ||
{ | ||
progressMonitor.CommandFailed(Exec, args, exitCode); | ||
|
@@ -45,9 +56,9 @@ private bool RunCommandAux(string args, bool redirectStandardOutput, out IList<s | |
} | ||
|
||
public bool RunCommand(string args) => | ||
RunCommandAux(args, redirectStandardOutput: false, out _); | ||
RunCommandAux(args, out _); | ||
|
||
public bool RunCommand(string args, out IList<string> output) => | ||
RunCommandAux(args, redirectStandardOutput: true, out output); | ||
RunCommandAux(args, out output); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity: Did you measure the performance impact of using this "Parallel" library instead of PLINQ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case, this is much nicer :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't. But I'm under the impression that they do the same.