Skip to content

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

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

Open
devoncarew opened this issue Jan 10, 2023 · 3 comments
Open
Labels
analyzer-stability area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. model-flow Implementation of flow analysis in analyzer/cfe model-performance Performance/memory issues in analyzer/cfe P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@devoncarew
Copy link
Member

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:

  • the project takes about twice as long to analyze after I've generated this file than it did before
  • when I open the file in vs code, the outline view takes a very long time to populate (even though when it finishes - 1-2 minutes later - the view only has ~200 symbols)

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 devoncarew added the legacy-area-analyzer Use area-devexp instead. label Jan 10, 2023
@devoncarew
Copy link
Member Author

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

@scheglov
Copy link
Contributor

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).

@scheglov scheglov added the P2 A bug or feature request we're likely to work on label Jan 12, 2023
@srawlins
Copy link
Member

CC @stereotype441 for FlowModel performance.

@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Mar 14, 2024
@johnniwinther johnniwinther added area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. model-flow Implementation of flow analysis in analyzer/cfe model-performance Performance/memory issues in analyzer/cfe and removed legacy-area-analyzer Use area-devexp instead. labels Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-stability area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. model-flow Implementation of flow analysis in analyzer/cfe model-performance Performance/memory issues in analyzer/cfe P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants