-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Dart Analyzer very slow/stuck #55281
Comments
@DanTup , do you see this? Have there been more reports of this kind? |
/ cc @bwilkerson |
I've not seen any other reports like this. 100% CPU certainly does not look healthy if it's persisting for a long period after initial analysis. @JonasJW a few questions:
|
We were having the same issue and using the Removing it completely seems to have solved the issue for us, are you using it too, and can you try to remove it to confirm it comes from there if you are ? |
/cc @scheglov |
@DanTup Thanks for the response and sorry for the late reply. code --status output:
To be honest, I'm not quite sure what you mean by your question about symlinks or how I can find out. Yes, this issue seems to have started just recently without making any noticeable changes such as updating SDKs, installing extensions, etc. Here are further screenshots, I hope this is the server timing page you meant. If you have any recommendations what I can try to fix this issue, I'm happy to try that. As mentioned, I have already tried uninstalling Flutter/Dart, VSCode, etc. at the moment I don't know what else I could try. |
For us updating |
@JonasJW thanks - the page I meant was the one marked "Timing" on the left. Can you also confirm whether you're using any analyzer plugins? A few comments above suggest You should be able to check for symlinks by running |
@DanTup thanks for the clarification! I don't use When I run
Is that anything out of the ordinary? Here the screenshots of the "Timing" page: |
That one doesn't look like a problem, but are there any that point back up the tree (eg. creating cycles or including other large parts of the disk in the the path)? It may be useful to enable the analyzer instrumentation log (this file can get very large - be sure to turn it off afterwards) and reproduce the issue, and see if there is anything in the log file that looks out of place while this happens (for example exceptions, or paths you would not expect to be analyzed with this project open being analyzed). You mentioned this only happens on large projects - are any of them public projects that I could test with (or that sharing logs from would not include anything sensitive)? |
Hi @DanTup, I apologize for taking so long to respond. I still have this issue and it's really slowing down my development process.
Here are a few symlinks, some point up but it doesn't appear to me that they would create a cycle
In total there are over 550 symlinks. Does any of this sound problematic? I also tried the analyzer instrumentation logs but I can't really find anything that appears out of place. However, this document seems to log all kinds of stuff and I'm not sure how to analyze it or what to look for. Yes, unfortunately, this project is private and can't be shared. I could probably share the analyzer instrumentation logs privately with you, if that would help. I recently tested this project on a windows laptop and the issue occurs as well. (Thus, I think completely reinstalling my mac won't even help fix it). These issues don't appear on new Flutter projects. Maybe I could try to download a big public project and see if I have problems with other bigger projects as well? If not it must be something specific with my project but I'm clueless about where the issue could be. |
Nothing above looks like an issue to me - the issue would be if the link points further up the tree so that walking the tree could cause endless cycles.
The most useful thing would be knowing what's being logged during the periods where performance is bad. So if the bad performance is during startup, it would be the start of the logs (until the first
I can't accept anything confidential (instrumentation logs can contain contents of opened files and paths/errors for other files in the workspace), but if you're able to reproduce this on a copy of the project with anything confidential removed (and perhaps only a single test file open), you might be able to get a log that doesn't contain anything confidential you can share. Something I forgot to ask earlier - can you confirm whether you have this option ticked in the VS Code (User or Workspace) settings? |
Understood, I will go back to the logs and look for these progress events. If I have something to share I will follow up on it here. The |
FWIW, my recommendation would be to not use that setting (and I should update the text). Although it sounds better for large projects, it was really added for a fairly specific case (command line editors that would provide the current working directory - which may be the user home dir - as the workspace folder). While the server will start up faster for very large workspaces, opening and closing files from different projects will trigger re-creating the analysis roots which can trigger "initial" analysis for those projects. It's beneficial if you're opening a folder that contains 100 projects and maybe only opening files from a handful, but if you're jumping between a large portion of the projects in the workspace, it's probably worse overall. |
@JonasJW what is your current experience with analysis performance? Are you still experiencing this weird behavior? |
@mraleph yes, I'm still experiencing performance issues |
@JonasJW are you able to reproduce this issue with any public projects? It might be easier to narrow down with an instrumentation log, but that log will contain parts of source code from the open projects. If it only occurs with this one specific internal project, is it possible to make a copy of it and see if you can narrow down what causes it (for example if it's made up of many packages, can you remove some of them to narrow down if it's caused by a specific package/set of packages)? Do you also know if this issue occurs when typing in any file, or just some subset? This issue could be similar to #56307 which may be caused by the number of files that need to be reanalyzed as you modify a file (see #56307 (comment) and #56307 (comment)). |
Maybe a related issue |
Hi @jensjoha I did all the steps to move to workspaces, I have only one |
With regards to the workspace feature, could it be that you have opened the folders separately instead of just opening the folder that contains the workspace? I'm not familiar with IntelliJ, so I don't know what the correct names are there, but in VSCode, if I without the workspace feature opened the main folder (with, for my test case "project1" and "project2" folders inside it) I got 3 contexts: The main folder, project1 and project2. With the workspace feature enabled, opening the main folder gives me just 1 context, whereas opening the projects individually (i.e. a VSCode 'workspace' with two folders (project1 and project2)) I get 2 contexts. If that's the case, could you try to just open that (in lack of better words) "main folder"? As for the crashing, is it that it just doesn't launch? Again I'm not familiar with the IntelliJ UI, but I would assume you'd need a full path to the SDK (say something like |
@jensjoha I have the full path, I only I hid it to post here. About the workspace, I have this structure, I open the main folder containing all the packages, apps and so on. |
@BenevidesLecontes can you check if you have any $ cd path-to-app_3.0
$ find . -iname '.dart_tool'
...
$ find . -iname 'pubspec.yaml' -exec grep -L 'resolution:.*workspace' '{}' ';' Both |
@mraleph I removed all These commands: |
@BenevidesLecontes this looks correct. It is puzzling that you get so many contexts then. Could you open Analyzer Diagnostics page and see what it says about those contexts, e.g. when I create a test workspace I get 1 context with multiple packages inside: Can you look through contexts that you have? Is workspace recognized correctly (e.g. you should have at least one context listing all your packages)? If it is recognized correctly - try to look what other contexts do you have. |
@mraleph I blurred some paths but this is what i have. I have |
@BenevidesLecontes this seems just one of the context, and it only has 7 packages inside. How do other contexts look like? I think |
@mraleph removed the |
@BenevidesLecontes do you have any analysis server plugins enabled?
When that work was done, it could break plugins because plugins would no longer get the context roots they expected. To fix this, roots are still created for any folder where an If plugins are enabled, it would be useful to try removing them from all |
@DanTup I have this in my analysis_options.yaml
|
Lately, working with Flutter has been really tough and frustrating. Most of the time, the Dart analyzer freezes after a hot restart, and I can’t do anything. Code completion becomes extremely slow, and undefined errors occur frequently. I even reinstalled macOS to resolve this issue, but the situation remains the same. We need to find a solution to this problem because it’s almost impossible to work like this right now. Click to see the log``` #0 ElementImpl2.enclosingElement2 (package:analyzer/src/dart/element/element.dart:3106:38) #1 _ReferenceFinder.visitAssignmentExpression (package:analysis_server/src/services/correction/dart/import_add_show.dart:71:51) #2 AssignmentExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:954:15) #3 ExpressionStatementImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:6366:17) #4 RecursiveAstVisitor.visitExpressionStatement (package:analyzer/dart/ast/visitor.dart:1099:10) #5 ExpressionStatementImpl.accept (package:analyzer/src/dart/ast/ast.dart:6362:50) #6 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:13009:20) #7 BlockImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:2051:17) #8 RecursiveAstVisitor.visitBlock (package:analyzer/dart/ast/visitor.dart:883:10) #9 BlockImpl.accept (package:analyzer/src/dart/ast/ast.dart:2047:50) #10 IfStatementImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:9730:20) #11 RecursiveAstVisitor.visitIfStatement (package:analyzer/dart/ast/visitor.dart:1273:10) #12 IfStatementImpl.accept (package:analyzer/src/dart/ast/ast.dart:9724:50) #13 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:13009:20) #14 BlockImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:2051:17) #15 RecursiveAstVisitor.visitBlock (package:analyzer/dart/ast/visitor.dart:883:10) #16 BlockImpl.accept (package:analyzer/src/dart/ast/ast.dart:2047:50) #17 BlockFunctionBodyImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:2007:12) #18 RecursiveAstVisitor.visitBlockFunctionBody (package:analyzer/dart/ast/visitor.dart:889:10) #19 BlockFunctionBodyImpl.accept (package:analyzer/src/dart/ast/ast.dart:1999:50) #20 FunctionExpressionImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:8624:11) #21 RecursiveAstVisitor.visitFunctionExpression (package:analyzer/dart/ast/visitor.dart:1213:10) #22 FunctionExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:8613:50) #23 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:13009:20) #24 ArgumentListImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:476:16) #25 RecursiveAstVisitor.visitArgumentList (package:analyzer/dart/ast/visitor.dart:823:10) #26 ArgumentListImpl.accept (package:analyzer/src/dart/ast/ast.dart:472:50) #27 InstanceCreationExpressionImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:10518:19) #28 RecursiveAstVisitor.visitInstanceCreationExpression (package:analyzer/dart/ast/visitor.dart:1309:10) #29 InstanceCreationExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:10507:15) #30 VariableDeclarationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:18577:19) #31 RecursiveAstVisitor.visitVariableDeclaration (package:analyzer/dart/ast/visitor.dart:1806:10) #32 VariableDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:18572:50) #33 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:13009:20) #34 VariableDeclarationListImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:18701:16) #35 RecursiveAstVisitor.visitVariableDeclarationList (package:analyzer/dart/ast/visitor.dart:1812:10) #36 VariableDeclarationListImpl.accept (package:analyzer/src/dart/ast/ast.dart:18695:15) #37 FieldDeclarationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:7042:16) #38 RecursiveAstVisitor.visitFieldDeclaration (package:analyzer/dart/ast/visitor.dart:1135:10) #39 FieldDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:7037:50) #40 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:13009:20) #41 ClassDeclarationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:2939:13) #42 RecursiveAstVisitor.visitClassDeclaration (package:analyzer/dart/ast/visitor.dart:937:10) #43 ClassDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:2929:50) #44 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:13009:20) #45 CompilationUnitImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:3621:21) #46 RecursiveAstVisitor.visitCompilationUnit (package:analyzer/dart/ast/visitor.dart:961:10) #47 CompilationUnitImpl.accept (package:analyzer/src/dart/ast/ast.dart:3614:50) #48 ImportAddShow.compute (package:analysis_server/src/services/correction/dart/import_add_show.dart:48:10) #49 AssistProcessor._addFromProducers.compute (package:analysis_server/src/services/correction/assist_internal.dart:207:24) #50 AssistProcessor._addFromProducers (package:analysis_server/src/services/correction/assist_internal.dart:228:15) #51 AssistProcessor.compute (package:analysis_server/src/services/correction/assist_internal.dart:181:5) #52 DartCodeActionsProducer.getAssistActions (package:analysis_server/src/lsp/handlers/code_actions/dart.dart:133:21) #53 OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14) #54 CodeActionHandler.handle.. (package:analysis_server/src/lsp/handlers/handler_code_actions.dart:235:20) #55 ErrorOrRecord2Extension.mapResults (package:analysis_server/src/lsp/error_or.dart:125:12) #56 ErrorOr.mapResult (package:analysis_server/src/lsp/error_or.dart:94:11) #57 ServerStateMessageHandler.handleMessage (package:analysis_server/src/lsp/handlers/handlers.dart:452:11) #58 LspAnalysisServer._handleRequestMessage (package:analysis_server/src/lsp/lsp_analysis_server.dart:1068:18) #59 LspAnalysisServer.handleMessage.. (package:analysis_server/src/lsp/lsp_analysis_server.dart:509:15) #60 OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14) #61 LspAnalysisServer.handleMessage. (package:analysis_server/src/lsp/lsp_analysis_server.dart:491:11)
|
In my tests conducted on the beta channel and a new Flutter project, the app randomly freezes during a hot restart. After a long period, the error below occurs, and the restart process completes. This issue happens randomly—sometimes there’s no problem even after several restarts, while other times it happens on the first attempt.
[+4206 ms] Skipping target: gen_localizations
[ ] Skipping target: gen_dart_plugin_registrant
[ ] Skipping target: _composite
[ ] complete
[ +3 ms] Scanned through 644 files in 2ms
[ ] <- reset
[ ] Compiling dart to kernel with 0 updated files
[ ] Processing bundle.
[ ] <- recompile package:flutter_analyzer/main.dart c9a01cee-4e05-4db5-8f4c-d2c2778fe0f9
[ ] <- c9a01cee-4e05-4db5-8f4c-d2c2778fe0f9
[ +1 ms] Bundle processing done.
[ +36 ms] Updating files.
[ ] Pending asset builds completed. Writing dirty entries.
[+60373 ms] Error writing "main.dart.dill" to DevFS: HttpException: Request has been aborted
[ ] trying again in a few - 9 more attempts left
[ +993 ms] DevFS: Sync finished
[ ] Synced 53.6MB.
[ ] <- accept |
@hasimyerlikaya it sounds like your problems are related to running several processes at once. Or at least, we can't tell if there is one culprit, from your description. Can you confirm that you are having a problem with the Dart Analyzer, meaning things like your IDE's Problems panel is slow to refresh, code completion is slow (which you do show in your screenshot), syntax highlight gets stale, things like that? What is your IDE? It sounds like you might be running your app alongside your IDE in a simulator or an emulator. Can you confirm that? What if you code for a long session in your IDE without running the simulator or emulator? Does the Dart Analyzer perform better then?
This is not a problem with the Dart Analyzer. Please open a new issue if you wish to report a bug with the Dart VM or with hot restart. |
@srawlins Apologies for the incomplete information. I should have provided a more detailed explanation. Development Environment: Issues Encountered After Flutter 3.27 Update:1. Hot Restart Issue: 2. Slow Code Completion: Next Steps: Let me know if you need further details! |
@mraleph Is there any workaround to allow this fix to hit |
I am not sure which specific fix you refer to. If this is related to TBH I am not sure we even have a clear idea of what problems are people experiencing in this particular issue - it might not be even be a single problem, but a combination of different problems. The best I can currently recommend is to 1) adopt workspaces if you work with monorepos. 2) possibly switch to newer Flutter channel.
@srawlins @pq @keertip ping on this question. I would like to understand if we still need to fix something with workspaces and analysis options? Because we are telling people to adopt this feature as a way to reduce memory usage and many successfully did it. But we also see in this issue that it might not work out of the box if you have nested analysis_options files. |
Hi there, I recently optimized my include: package:flutter_lints/flutter.yaml
linter:
rules:
avoid_print: false # Allow print statements, useful for debugging
unused_local_variable: ignore # Ignore warnings about unused local variables
always_declare_return_types: true # Ensure all methods have a return type
prefer_const_constructors: true # Prefer const constructors for better performance
avoid_unnecessary_containers: true # Avoid redundant containers in UI
use_key_in_widget_constructors: true # Enforce using keys in widget constructors
prefer_final_fields: true # Use `final` for fields that are not reassigned
sort_child_properties_last: true # Improve readability of widget tree definitions
analyzer:
exclude:
- build/** # Exclude generated files in the build directory
- .dart_tool/** # Exclude Dart tool-generated files
- gen/** # Exclude other generated code, if any
errors:
invalid_annotation_target: ignore # Ignore warnings for invalid annotations
missing_required_param: error # Catch missing required parameters early
unused_import: warning # Flag unused imports but at a warning level
deprecated_member_use: warning # Warn about usage of deprecated members
unnecessary_cast: ignore # Ignore unnecessary casts for simpler code
# Optional: Stronger type safety
strong-mode:
implicit-casts: false # Prevent implicit casting, requiring explicit casts
implicit-dynamic: false # Disable implicit dynamic typing for better type safety Why This Might Help:
I've noticed a tangible speed improvement since adopting this setup. Perhaps you could give it a try? Let me know if you need assistance implementing it! |
@denyocr93 Thanks for the information! You mentioned that you'd optimized the file but didn't explicitly say what changes you'd made, only what the final result was. I'm guessing that the exclusions were absent before, but I'm wondering whether there were other changes that might also have impacted the performance, such as the use of plugins or the enablement of some lints that have been removed. |
I am facing the same issue. I've already commented issue#5251 but I think it can be usefull to share it here. I’ve recorded my screen and captured logs while experiencing slow reload window, slow code completion and Below, you’ll find the video, the log, and the output of Code_vgEcAWegu4_V1.mp4Workspace Environment
Output from 'dart info'
If providing this information as part of reporting a bug, please review the information General info
Project info
Process info
Output from 'flutter doctor'
Let me know if you need further informations. |
This was my previous configuration: {
"[dart]": {
"editor.formatOnSave": false,
"editor.formatOnType": false,
"editor.rulers": [
80
],
"editor.selectionHighlight": false,
"editor.suggest.snippetsPreventQuickSuggestions": false,
"editor.suggestSelection": "first",
"editor.tabCompletion": "onlySnippets",
"editor.wordBasedSuggestions": "off",
"editor.defaultFormatter": "Dart-Code.dart-code"
}
} Previously, I had this part enabled: "editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
} I changed it to: {
"[dart]": {
"editor.formatOnSave": false,
"editor.formatOnType": false,
"editor.rulers": [
80
],
"editor.selectionHighlight": false,
"editor.suggest.snippetsPreventQuickSuggestions": false,
"editor.suggestSelection": "first",
"editor.tabCompletion": "onlySnippets",
"editor.wordBasedSuggestions": "off",
"editor.defaultFormatter": "Dart-Code.dart-code"
}
} It seems like enabling I also removed this configuration: "editor.codeActionsOnSave": {
"source.fixAll": "explicit"
} I really liked this feature, but I had to remove it as of January 8 to improve performance. |
@denyocr93, this is actually the setting that runs something similar to "editor.codeActionsOnSave": {
"source.fixAll": "explicit"
} You can set these to "editor.formatOnSave": true,
"editor.formatOnType": true, |
but it is a very helpful feature, I don’t want to disable it |
@hasimyerlikaya We're experiencing this issue with the same symptoms: Created an issue for it here: flutter/flutter#161466. Would be grateful for you contribute any findings as this is a major issue for us and we suspect some others. |
@stx I’ve been working with the iOS simulator for a while, and I haven’t experienced this issue. Working with a real device was truly painful. Recently, the iOS 18.2.1 update was released. Restarting seemed to improve things a bit with that update, but since I haven’t used it much, I can’t say for sure. If you haven’t updated yet, you might want to try version 18.2.1. |
Is there a known workaround? I'm using dart 3.6.0, flutter 3.27.1, vscode 1.93.1 and it's running so slow it's almost unusable and it's affecting my productivity tremendously. |
@choim4389 please file a new issue with details about what problem you are facing, which what product. |
Dart & Flutter has suddenly become unusable slow in VSCode. Intellisense won't load within 30+ seconds, syntax highlighting won't update, jumping to code definitions loads infinitely, etc.
This seems to be especially the case on bigger projects, on a newly created project it works fine. I tried switching to Android Studio which seems to behave similarly (maybe a little better).
I tried uninstalling all extensions, even completely removing VSCode with any data stored and reinstalling it. As soon as I install the Dart extension, it is unusable. I also tried setting the following settings:
I'm on macOS 14.4, VSCode Version 1.87.2 (Universal),
In the Activity Monitor, there is the
dart:analysis_server.dart.snapshot
process running with around 1 GB of used memory. I'm not sure if this is normal.Here is a screenshot from the Dart Analyzer (which I'm also having trouble opening)
dart info
output:General info
Project info
Process info
Any recommendations on how I could possible fix this would be very welcome!
The text was updated successfully, but these errors were encountered: