Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reading MPR#6542 it seems like 8db1b59 brings a noticeable speedup when typechecking classes, at the cost of make the code of
type_cases
noticeably more convoluted.Looking at the code, the following can be deduced:
propagate = false
) iff.ty_arg
is generic and the matching only has one clause, consisting of a variableunify_var
with a fresh variable for every subpattern)However, given the first condition, the calls to generalize that are avoided should actually be noops even if we ran them.
So the speed up comes from avoiding the call to
unify_var
(which is what's hinted at in the MPR, even though the code was slightly different at the time).As it turns out, the same speed-up can be achieved by a more straightforward change: passing the arguments in the correct order when calling
unify_var
. Indeed, with the way it is currently called in trunk, it always degrades tounify
.For benchmarking I reused the same test case as given in the MPR, that is:
I timed the compilation of that file (and a slightly bigger one where I have 8k methods instead of 2k) a few times, with various compilers, here are the results: