Skip to content
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

Simplify verify throw and remove unnecessary usings #6992

Closed
wants to merge 19 commits into from

Conversation

Forgind
Copy link
Member

@Forgind Forgind commented Oct 25, 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.

When calculating a value to see if we can do a type of comparison, store
that value so we don't have to calculate it again. Use Try*Evaluate
instead of Can*Evaluate and *Evaluate.
Removes all *Evaluate and Can*Evaluate except in OperatorExpressionNodes, for which CanBoolEvaluate always returns true, so using a simple BoolEvaluate makes sense.

Note that for the NumericComparisonExpressionNode, we could save a tiny amount of time by only calling TryEvaluate when it's actually used (and using if/else as before), but that would since something can be both a number and a version, that would mean we would have to check both regardless of what we had previously found, which means it would be noticeably messier for (probably) very little perf gain, so I opted against that. Switch statements are so pretty 🙂
Apparently that's the best supported way
I tested once with and once without this change, and with this change, Evaluate was 3% faster...that sounds noisy, but I'll still take it.
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
@Forgind Forgind force-pushed the simplify-verifyThrow branch 2 times, most recently from f521fa4 to fd02288 Compare October 27, 2021 00:53
Rather than checking whether false is false.
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.
@Forgind Forgind closed this Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant