extension slows down intellisense features
Actual Behavior
When this extension is enabled intellisense features such as go-to-definition and hovering for type info are noticeably slower than usual, taking several seconds when they would normally be close to instantaneous. This includes for symbols that are not part of a GraphQl query such as TypeScript variables.
Expected Behavior
Steps to Reproduce the Problem Or Description
Specifications
- GraphQL for VSCode Extension Version: 0.3.18
- VSCode Version: 1.61.1
- OS Name: Mac OS
- OS Version: 11.6
Logs Of TS Server || GraphQL Language Service
10/15/2021, 4:28:05 PM [4] (pid: 10297) graphql-language-service-usage-logs: {"type":"usage","messageType":"initialize"}
10/15/2021, 4:28:24 PM [4] (pid: 10297) graphql-language-service-usage-logs: {"type":"usage","messageType":"textDocument/didOpen","projectName":"default","fileName":"file:///Users/nathanielpalmer/simplisafe/projects/ss-ecomm-frontend/src/templates/PartnerPage.tsx"}
10/15/2021, 4:31:50 PM [4] (pid: 10297) graphql-language-service-usage-logs: {"type":"usage","messageType":"textDocument/didOpen","projectName":"default","fileName":"file:///Users/nathanielpalmer/simplisafe/projects/ss-ecomm-frontend/src/componentMappings.ts"}
[Error - 4:31:50 PM] Request textDocument/documentSymbol failed.
Message: Request textDocument/documentSymbol failed with message: A cached document cannot be found.
Code: -32603 ```
this may be because we have to cache many files when doing different lookups because we don't have an import path to trace like the typescript extension
hopefully new versions are better with performance, but there are many places to improve
for example:
- you open the extension. it automatically caches all files
- codegen re-generates a file that isn't open in the editor. LSP has no way of knowing that file changed.. or does it? in
vscode-graphqlclientextension.ts, we create aworkspace.createFileSystemWatcher()forsynchronize.fileEventswhich may or may not be listening to changes to files that have not been opened... I should check into this! - because we don't know if the language service cache has been updated to create these potentially untracked file changes, on each lookup event we re-build the schema and file caches which I imagine could cause this performance impact. I imagine it's even more dramatic when people try to install this extension in codespaces or other web vscode projects
I have a similar issue, when i open a project in vscode, my mac goes nuts spawning a "rg" process that totally kill performance and battery. As soon as i interrupt those processes, Graphql: Language Feature Support crashes.
handleWorkspaceSymbolRequest is extremely slow. With some manually injected logging lines, using vscode's quick pick menu (ctrl/cmd+p) to search for a file results in the following:
[Info - 12:47:04 AM] handleWorkspaceSymbolRequest {"query":"server"}
[Info - 12:47:08 AM] handleWorkspaceSymbolRequest file:///redacted/13000-lines-long/schema.graphql 3496ms docSymbols 10543
[Info - 12:47:08 AM] handleWorkspaceSymbolRequest 3497ms 3 documents 10543 symbols of 0
[Info - 12:47:08 AM] handleWorkspaceSymbolRequest {"query":"server/tests"}
[Info - 12:47:11 AM] handleWorkspaceSymbolRequest file:///Redacted/13000-lines-long/schema.graphql 3326ms docSymbols 10543
[Info - 12:47:11 AM] handleWorkspaceSymbolRequest 3327ms 3 documents 10543 symbols of 0
This indicates to me that caching needs to be improved for workspace symbol requests. For now, i'm just disabling that feature by manually commenting out the feature in my local extensions folder.
logging code
async handleWorkspaceSymbolRequest(params) {
if (!this._isInitialized) {
return [];
}
this._logger.info(`handleWorkspaceSymbolRequest ${JSON.stringify(params)}`)
if (params.query !== "") {
const start = Date.now();
const documents = this._getTextDocuments();
const symbols = [];
await Promise.all(documents.map(async ([uri]) => {
const cachedDocument = this._getCachedDocument(uri);
if (!cachedDocument?.contents[0]?.query) {
return [];
}
const start = Date.now();
const docSymbols = await this._languageService.getDocumentSymbols(cachedDocument.contents[0].query, uri);
const duration = Date.now() - start;
this._logger.info(`handleWorkspaceSymbolRequest ${uri} ${duration}ms docSymbols ${docSymbols.length}`)
symbols.push(...docSymbols);
}));
const results = symbols.filter((symbol) => (symbol === null || symbol === void 0 ? void 0 : symbol.name) && symbol.name.includes(params.query));
const duration = Date.now() - start;
this._logger.info(`handleWorkspaceSymbolRequest ${duration}ms ${documents.length} documents ${symbols.length} symbols of ${results.length}`)
return results;
}
return [];
}
Hello! I have a similar issue with one of my projects. But can't reproduce it with exact steps.
Sometimes it takes more than 10-20 seconds to display intellisense features (and 100% cpu load). Today I tried to debug this extention, but it worked well. Maybe the graphql-codegen in watch mode can cause an issue in my case
Can someone share example and steps to repro?
To reproduce, I would try downloading a large graphql schema, such as github's graphql api, put it in your repository, ensure that it's part of your projects in your graphql.config.json, and then see what happens.