Skip to content

Conversation

ToddGrun
Copy link
Contributor

This code previously created an ArrayBuilder over the rawArguments given and did some funky manipulations in support of response file handling.

This PR removes that extra ArrayBuilder and it's associated allocations (these lists end up being large enough to exceed the pooling threshold). I think the new code is also a bit easier to understand, particularly in the non-response file section of the code. (No copying into a list, reversing that list, walking it backwards, walking another list backwards, copying into an unused section of the first list, making that section used again, etc)

This only reduces allocations by ~5 MB when opening the roslyn sln, but it also seems simpler and easier to understand.

This code previously created an ArrayBuilder over the rawArguments given and did some funky manipulations in support of response file handling.

This PR removes that extra ArrayBuilder and it's associated allocations (these lists end up being large enough to exceed the pooling threshold). I think the new code is also a bit easier to understand, particularly in the non-response file section of the code. (No copying into a list, reversing that list, walking it backwards, walking another list backwards, copying into an unused section of the first list, making that section used again, etc)

This only reduces allocations by ~5 MB when opening the roslyn sln, but it also seems simpler and easier to understand.
@ToddGrun ToddGrun requested a review from a team as a code owner June 25, 2025 22:09
args.ReverseContents();
var argsIndex = args.Count - 1;
while (argsIndex >= 0)
var argsEnumerator = rawArguments.GetEnumerator();
Copy link
Contributor

@AlekseyTs AlekseyTs Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argsEnumerator

Probably should dispose at the end. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed with recursive simplificiation

while (argsEnumerator.MoveNext())
notProcessedSplitList.Add(argsEnumerator.Current);

argsEnumerator = notProcessedSplitList.GetEnumerator();
Copy link
Contributor

@AlekseyTs AlekseyTs Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argsEnumerator

Probably should dispose before overwriting. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed with recursive simplificiation

// Ignores /noconfig option specified in a response file
if (!string.Equals(newArg, "/noconfig", StringComparison.OrdinalIgnoreCase) && !string.Equals(newArg, "-noconfig", StringComparison.OrdinalIgnoreCase))
if (string.Equals(newArg, "/noconfig", StringComparison.OrdinalIgnoreCase) || string.Equals(newArg, "-noconfig", StringComparison.OrdinalIgnoreCase))
Copy link
Contributor

@AlekseyTs AlekseyTs Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (string.Equals(newArg, "/noconfig", StringComparison.OrdinalIgnoreCase) || string.Equals(newArg, "-noconfig", StringComparison.OrdinalIgnoreCase))

Consider keeping the original condition to reduce the unnecessary changes and keeping the diff to a necessary minimum. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

var argsIndex = args.Count - 1;
while (argsIndex >= 0)
var argsEnumerator = rawArguments.GetEnumerator();
while (argsEnumerator.MoveNext())
Copy link
Contributor

@AlekseyTs AlekseyTs Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while (argsEnumerator.MoveNext())

I would like to suggest an alternative approach.

  1. Extract the body of this loop into a local function, let's call it "void processArg(string arg)". It should start with trimming the arg, and do what the body of the loop does, assuming that a continue is replaced with a return.
  2. Change this loop to plain foreach over rawArguments, calling the new local function as the body.
  3. Inside parseResponseFile, instead of doing notProcessedSplitList.Add(newArg);, call processArg(newArg). #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea, implemented in commit 2. Makes the code even easier to understand.

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 1)

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 2)

@ToddGrun ToddGrun merged commit 893942c into dotnet:main Jun 26, 2025
24 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jun 26, 2025
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants