Skip to content

ReplacingEV uses two arrays instead of dictionary - #19858

Merged
roji merged 2 commits into
masterfrom
ReplaceFaster
Feb 10, 2020
Merged

roji merged 2 commits into
masterfrom
ReplaceFaster

Conversation

@roji

@roji roji commented Feb 10, 2020

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor

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
Copy Markdown
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