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

Decompiler takes quadratic time for large array initializers #1202

Closed
dgrunwald opened this issue Jul 14, 2018 · 1 comment
Closed

Decompiler takes quadratic time for large array initializers #1202

dgrunwald opened this issue Jul 14, 2018 · 1 comment

Comments

@dgrunwald
Copy link
Member

dgrunwald commented Jul 14, 2018

During profiling I found (at least) two hotspots caused by long array initializers interacting badly with the NRefactory AST design.

  1. TranslateArrayInitializer()
    The loop condition
while (container.Count > 0 && container.Peek().Elements.Count == dimensionSizes[container.Count - 1]) {
    container.Pop();
}

consumes a large amount of time, because the Elements.Count property getter is actually O(N). The while-loop condition is false most of the time, but there's an outer loop adding to container.Peek().Elements, so an array initializer with N elements performs N get_Count calls, taking O(N²) overall time.

  1. InsertSpecialsDecorator.WriteSpecialsUpToRole()
    Here we are looking for the non-existing comma tokens. For each place where there should be a comma we scan all following children, so that's quadratic. The problem is hard to fix given the InsertSpecialsDecorator design, but an easy workaround would be to emit the comma tokens it is looking for.

In the case of the NRefactory roundtrip test, fixing these performance bugs should have a significant impact on the overall decompilation time (at least 25%).

@dgrunwald
Copy link
Member Author

I think 27efe1b fixed this; I can't think of a better fix that doesn't involve changing the whole AST design.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant