dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.09k stars 1.56k forks source link

potential performance issue in the analyzer with large switch statements #50962

Open devoncarew opened 1 year ago

devoncarew commented 1 year ago

I'm working on some generated code and am seeing a potential performance issue in the analyzer with large switch statements. I have a switch statement with 24,615 cases and notice that:

Perhaps there's some non-linear algorithm involving switch statements? The file itself is large - 1,379kb - but I'm working with other files that size or larger and not seeing the same issue.

devoncarew commented 1 year ago

To repro the issue, see the br_table.0.dart file here: https://github.com/devoncarew/wasmd/tree/main/test/spec/br_table.

scheglov commented 1 year ago

Yes, Observatory shows quite interesting picture. There are so far two big performance issues visible:

  1. FlowAnalysisHelper.getLabelTarget - probably indeed O(n^2)
  2. FlowModel._clone - at the end there are 24618 in variableInfo map. It looks that each case in the switch adds one new entry to variableInfo, so it is also O(n^2).
srawlins commented 1 year ago

CC @stereotype441 for FlowModel performance.