microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.52k stars 1.55k forks source link

Autocomplete becomes really slow when including third party library #5864

Open akurniawan opened 4 years ago

akurniawan commented 4 years ago

Type: LanguageService

Describe the bug

I am trying to implement simple demo from https://pytorch.org/cppdocs/frontend.html. The problem occurs when I include #include <torch/torch.h>. The auto complete would not show up for seconds, sometimes it doesn't even show up and I need to force it by pressing ^+Space. I expect to have a cache file generated on the default path to cache the precompiled headers from that library, however I couldn't find it. I also tried to change the cache path, but still no files are generated.

Steps to reproduce

  1. Copy and follow instruction in https://pytorch.org/cppdocs/frontend.html on End-to-end Example section
  2. Include #include <torch/torch.h>
  3. Start typing. In my case even typing struct would not show any the auto complete at all

The following is my settings.json

{
    "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
}

I don't use c_cpp_properties.json And the following is my settings.json when I tried to change the cache path

{
    "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
    "C_Cpp.intelliSenseCachePath": ".vscode"
}

I only find ipch/<some_hash_id> folder inside .vscode, no files are generated

Expected behavior

Instant suggestion for autocomplete

C/C++: Log Diagnostics ``` -------- Diagnostics - 7/30/2020, 9:06:27 PM Version: 0.29.0 Current Configuration: { "name": "Mac", "includePath": [ "${workspaceFolder}/**" ], "defines": [], "macFrameworkPath": [], "compilerPath": "/usr/local/bin/gcc-10", "cStandard": "c11", "cppStandard": "gnu++14", "intelliSenseMode": "clang-x64", "compilerArgs": [], "configurationProvider": "ms-vscode.cmake-tools", "browse": { "path": [ "${workspaceFolder}/**" ], "limitSymbolsToIncludedHeaders": true } } Custom browse configuration: { "browsePath": [ "/volumes/workspace/learning/torchcpp/build/cmakefiles", "/volumes/workspace/learning/torchcpp/third_party/libtorch/include", "/volumes/workspace/learning/torchcpp/third_party/libtorch/include/torch/csrc/api/include", "/volumes/workspace/learning/torchcpp" ], "standard": "gnu++14", "compilerPath": "/usr/bin/clang++", "compilerArgs": [ "-g", "-isysroot", "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk", "-std=c++14", "-std=gnu++14" ] } Custom configurations: [ /Volumes/Workspace/learning/torchcpp/main.cpp ] { "defines": [], "standard": "gnu++14", "includePath": [ "/volumes/workspace/learning/torchcpp/third_party/libtorch/include", "/volumes/workspace/learning/torchcpp/third_party/libtorch/include/torch/csrc/api/include" ], "intelliSenseMode": "clang-x64", "compilerPath": "/usr/bin/clang++", "compilerArgs": [ "-g", "-isysroot", "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk", "-std=c++14", "-std=gnu++14" ] } Translation Unit Mappings: [ /Volumes/Workspace/learning/torchcpp/main.cpp ]: /Volumes/Workspace/learning/torchcpp/main.cpp Translation Unit Configurations: [ /Volumes/Workspace/learning/torchcpp/main.cpp ]: Process ID: 32992 Memory Usage: 113 MB Compiler Path: /usr/bin/clang++ Includes: /Volumes/Workspace/learning/torchcpp/third_party/libtorch/include /Volumes/Workspace/learning/torchcpp/third_party/libtorch/include/torch/csrc/api/include /Library/Developer/CommandLineTools/usr/include/c++/v1 /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3/include /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include /Library/Developer/CommandLineTools/usr/include Frameworks: /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks Standard Version: c++14 IntelliSense Mode: clang-x64 Other Flags: --clang --clang_version=110003 Total Memory Usage: 113 MB ```
Language Server Logs ``` textDocument/didChange: file:///Volumes/Workspace/learning/torchcpp/main.cpp cpptools/textEditorSelectionChange textDocument/didChange: file:///Volumes/Workspace/learning/torchcpp/main.cpp cpptools/textEditorSelectionChange textDocument/didChange: file:///Volumes/Workspace/learning/torchcpp/main.cpp cpptools/textEditorSelectionChange textDocument/didChange: file:///Volumes/Workspace/learning/torchcpp/main.cpp cpptools/textEditorSelectionChange cpptools/getFoldingRanges: file:///Volumes/Workspace/learning/torchcpp/main.cpp (id: 553) textDocument/didChange: file:///Volumes/Workspace/learning/torchcpp/main.cpp cpptools/abortRequest cpptools/textEditorSelectionChange textDocument/documentHighlight: file:///Volumes/Workspace/learning/torchcpp/main.cpp (id: 554) sending 1 changes to server sending 1 changes to server sending 1 changes to server sending 1 changes to server sending 1 changes to server cpptools/finishUpdateSquiggles Error squiggle count: 9 Update IntelliSense time (sec): 3.702 cpptools/getFoldingRanges: file:///Volumes/Workspace/learning/torchcpp/main.cpp (id: 555) textDocument/completion: file:///Volumes/Workspace/learning/torchcpp/main.cpp (id: 556) auto_complete::handle_completion: file:///Volumes/Workspace/learning/torchcpp/main.cpp (47:7) Offering completion cpptools/getCodeActions: file:///Volumes/Workspace/learning/torchcpp/main.cpp (id: 557) cpptools/getSemanticTokens: file:///Volumes/Workspace/learning/torchcpp/main.cpp (id: 558) cpptools/getCodeActions: file:///Volumes/Workspace/learning/torchcpp/main.cpp (id: 559) textDocument/didSave: file:///Volumes/Workspace/learning/torchcpp/main.cpp cpptools/fileChanged: file:///Volumes/Workspace/learning/torchcpp/main.cpp cpptools/getDocumentSymbols: file:///Volumes/Workspace/learning/torchcpp/main.cpp (id: 560) cpptools/getDocumentSymbols tag parsing file: /Volumes/Workspace/learning/torchcpp/main.cpp completionItem/resolve (id: 561) idle loop: reparsing the active document Checking for syntax errors: file:///Volumes/Workspace/learning/torchcpp/main.cpp Queueing IntelliSense update for files in translation unit of: /Volumes/Workspace/learning/torchcpp/main.cpp cpptools/finishUpdateSquiggles Error squiggle count: 10 Update IntelliSense time (sec): 0.26 cpptools/getSemanticTokens: file:///Volumes/Workspace/learning/torchcpp/main.cpp (id: 562) cpptools/getCodeActions: file:///Volumes/Workspace/learning/torchcpp/main.cpp (id: 563) Database safe to open ```

Screenshots

Additional context

sean-mcmanus commented 4 years ago

I think intelliSenseCachePath needs to be a full path. Can you try "${workspaceFolder}/.vscode"?

Some performance related fixes have been made in the configuration provider scenario with our pending 0.30.0-insiders update, but I haven't checked yet if this issue is fixed by that yet.

akurniawan commented 4 years ago

Thank you very much for the suggestion @sean-mcmanus. It works for the intelliSenseCachePath, but the latency is not getting better, unfortunately. Do you have any other suggestion that I can try?

sean-mcmanus commented 4 years ago

I downloaded the https://download.pytorch.org/libtorch/cpu/libtorch-macos-1.6.0.zip but it doesn't have a torch.h file. Do you know how to get that?

akurniawan commented 4 years ago

It's on libtorch/include/torch/csrc/api/include/torch. I needed to add "${workspaceFolder}/libtorch/**" to includePath on c_cpp_property.json

sean-mcmanus commented 4 years ago

I'm not seeing a performance issue, but I'm seeing autocomplete not working at all for fc1. Is that what you're seeing? Or do you have more info how I can reproduce the slowness? What do you mean by typing "struct" doesn't show autocomplete? Do you mean the struct keyword isn't completing or do you expect something else to complete after the struct keyword?

sean-mcmanus commented 4 years ago

The IntelliSense process is crashing when completion is invoked on fc1 -- the restarting of the IntelliSense process after the crash could be what you see as slowness as the process has to restart.

sean-mcmanus commented 4 years ago

Oh, well, the crash I'm seeing is with 0.30.0-insiders (it's a regression). I'm not repriong any bug with 0.29.0 -- let me know if you have more repro details for 0.29.0.

akurniawan commented 4 years ago

The performance issue is related to showing suggestions when I typed something. Struct is one of the examples. I expect when I type struct it will show as follows

image

To give all of those suggestions would take a while (1s or more), sometimes even have to be forcedly triggered by ctrl+space.

I can still see fc1's suggestions, but it's the same case with struct (need to be triggered by ctrl+space).

I expect the autocomplete will show up instantly when I type a half-finished words such as str for struct, std::co for std::cout, etc. I also expect the autocomplete will give suggestions instantly when I type nn:: to show the list of classes and functions that are available on that namespace.

sean-mcmanus commented 4 years ago

Yeah, I'm not reproing any slowness with completion (it's fast for me with 0.29.0).

I see error squiggles in your logging so that could be the cause. Are you able to fix your error squiggles?

If you could use a Mac profiler such as XCode's "instruments" tool on cpptools or cpptools-srv to see what the call stacks are contributing to the slowness that could help us diagnose what is going on. We might add some documentation to our wiki on how do that profiling later on.

magwa101 commented 3 years ago

I'm on a MBP Catalina 10.15.7 trying to developer Unreal Engine 4.26. It's unusably slow. Interestingly first "F12" symbol lookup can be very fast, next one takes seconds, 10 or 20. Is this bug being actively looked at?