Avoid calling indexOf
when checking array element types
#18619
Merged
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.
Shlemiel gets a job as a type checker, checking the contextual types of array elements. On the first day he takes his array contextual type out to the AST and finishes 300 elements of the array. "That's pretty good!" says his boss, "you're a fast worker!" and pays him a kopeck.
The next day Shlemiel only checks 150 elements. "Well, that's not nearly as good as yesterday, but you're still a fast worker. 150 elements is respectable," and pays him a kopeck.
The next day Shlemiel checks 30 elements of the array. "Only 30!" shouts his boss. "That's unacceptable! On the first day you did ten times that much work! What's going on?"
"I can't help it," says Shlemiel. "Every day I get farther and farther away from the beginning of the array!"
indexOf
was causing us to take ever-increasing time when for every array element, we would start counting again from the beginning of the array to find our position. (This only happens if the array has a contextual type.) This is an instance of a general problem where we climb ancestors to recompute information instead of passing it down directly.I ran the performance tests and saw no negative effect on checker time, probably because our tests don't use lots of long arrays.