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

ReplacingEV uses two arrays instead of dictionary #19858

Merged
merged 2 commits into from
Feb 10, 2020
Merged

ReplacingEV uses two arrays instead of dictionary #19858

merged 2 commits into from
Feb 10, 2020

Conversation

roji
Copy link
Member

@roji roji commented Feb 10, 2020

ReplacingExpressionVisitor held original and replacement expressions in a dictionary. Unfortunately that means hash code calculation occurs exponentially, as each TryGetValue on the dictionary must traverse the entire tree.

Replaced with two lists and a simple Equals check, which is much faster.

Fixes #19737

ReplacingExpressionVisitor held original and replacement expressions
in a dictionary. Unfortunately that means hash code calculation occurs
exponentially, as each TryGetValue on the dictionary must traverse
the entire tree.

Replaced with two lists and a simple Equals check, which is much
faster.

Fixes #19737
}

public ReplacingExpressionVisitor([NotNull] IDictionary<Expression, Expression> replacements)
public ReplacingExpressionVisitor([NotNull] Expression[] originals, [NotNull] Expression[] replacements)
Copy link
Member

Choose a reason for hiding this comment

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

Breaking change if patching.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep. We could leave the previous constructor and build arrays out of the keys/values.

@roji roji merged commit 7c9fc8a into master Feb 10, 2020
@roji roji deleted the ReplaceFaster branch February 10, 2020 21:27
roji added a commit that referenced this pull request Feb 10, 2020
ReplacingExpressionVisitor held original and replacement expressions
in a dictionary. Unfortunately that means hash code calculation occurs
exponentially, as each TryGetValue on the dictionary must traverse
the entire tree.

Replaced with two lists and a simple Equals check, which is much
faster.

Fixes #19737

(cherry picked from commit 7c9fc8a)
roji added a commit that referenced this pull request Feb 14, 2020
ReplacingExpressionVisitor held original and replacement expressions
in a dictionary. Unfortunately that means hash code calculation occurs
exponentially, as each TryGetValue on the dictionary must traverse
the entire tree.

Replaced with two lists and a simple Equals check, which is much
faster.

Fixes #19737

(cherry picked from commit 7c9fc8a)
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.

Exponential hash code calculation in ReplacingExpressionVisitor
3 participants