Skip to content

Conversation

@Forgind
Copy link
Contributor

@Forgind Forgind commented Oct 29, 2021

This has a little random cleanup plus moving the condition outside VerifyThrow calls if simply calling the method would do a nontrivial amount of work. The fourth commit switches VerifyThrow* to Throw* as appropriate.

I haven't measured the performance impact. The first and fourth commits should have ~0 impact, though technically the fourth commit makes it slightly faster in the failure case (by one branch). The third helps us avoid a couple small allocations. The second lets us avoid a nontrivial amount of work in an extremely common case, so if this has a positive perf impact, I would suspect that commit.

It should be easiest to look at this commit-by-commit.

These statements only do anything if the condition is false, but they evaluate their arguments either way. These do nontrivial work when evaluating their arguments, so figure out if we should skip it early. This is specifically tuned to BoolEvaluate (part of evaluating conditions)
Slightly reduce other work done
Rather than checking whether false is false.
/* helpfully display unexpanded token and expanded result in error message */
isLeftNum ? RightChild.GetUnexpandedValue(state) : LeftChild.GetUnexpandedValue(state),
isLeftNum ? RightChild.GetExpandedValue(state) : LeftChild.GetExpandedValue(state));
if ((!isLeftNum && !isLeftVersion) || (!isRightNum && !isRightVersion))
Copy link
Member

Choose a reason for hiding this comment

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

💗 simple change yet the code is FAR more readable

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 to mention performant! This prevents us from randomly expanding values when we don't expect to need them.

else if (actualSolutionFiles.Count > 1)
{
InitializationException.VerifyThrow(false, projectDirectory == null ? "AmbiguousProjectError" : "AmbiguousProjectDirectoryError", null, projectDirectory);
InitializationException.VerifyThrow(false, projectDirectory == null ? "AmbiguousProjectError" : "AmbiguousProjectDirectoryError", null, projectDirectory, false);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Since every other VerifyThrow(false,... was turned into Throw(..., should we make an overload for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There kinda already is one:
InitializationException.Throw(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword(projectDirectory == null ? "AmbiguousProjectError" : "AmbiguousProjectDirectoryError", projectDirectory), null);

Do you like that better? I don't really care either way. The VerifyThrow --> Throw change should have virtually no user impact.

@Forgind Forgind added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label Nov 1, 2021
@rokonec rokonec merged commit 24b3318 into dotnet:main Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants