Skip to content
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

perf(lsp): Only evict caches on JS side when things actually change #23293

Merged
merged 6 commits into from
Apr 11, 2024

Conversation

nathanwhit
Copy link
Member

@nathanwhit nathanwhit commented Apr 9, 2024

Currently we evict a lot of the caches on the JS side of things on every request, namely script versions, script file names, and compiler settings (as of #23283, it's not quite every request but it's still unnecessarily often).

This PR reports changes to the JS side, so that it can evict exactly the caches that it needs too. We might want to do some batching in the future so as not to do 1 request per change.

@nathanwhit nathanwhit force-pushed the lsp-granular-js-cache-eviction branch from 1e8dc13 to 7d33ea2 Compare April 9, 2024 16:07
@bartlomieju
Copy link
Member

bartlomieju commented Apr 9, 2024

I can no longer see op_script_version op calls in the profile (createProgram goes from 50ms to 10ms), however I get these errors:

Failed to request to tsserver TypeError: Cannot read properties of undefined (reading 'kind')
    at isVariableDeclaration (ext:deno_tsc/00_typescript.js:26883:17)
    at isSingleVariableDeclaration (ext:deno_tsc/00_typescript.js:140911:12)
    at tryGetFunctionFromVariableDeclaration (ext:deno_tsc/00_typescript.js:140914:10)
    at getFunctionInfo (ext:deno_tsc/00_typescript.js:140898:18)
    at Object.getRefactorActionsToConvertFunctionExpressions [as getAvailableActions] (ext:deno_tsc/00_typescript.js:140819:18)
    at ext:deno_tsc/00_typescript.js:138302:224
    at flatMapIterator (ext:deno_tsc/00_typescript.js:333:21)
    at flatMapIterator.next (<anonymous>)
    at arrayFrom (ext:deno_tsc/00_typescript.js:870:16)
    at Object.getApplicableRefactors (ext:deno_tsc/00_typescript.js:138300:12)
[Error - 21:14:39] Request textDocument/codeAction failed.
  Message: Invalid request
  Code: -32600 
{"type":"mark","name":"lsp.code_lens","count":10,"args":{"textDocument":{"uri":"file:https:///Users/ib/dev/apps/decohub/apps/linx.ts"}}},
{"type":"measure","name":"lsp.code_lens","count":10,"duration":0.004},
{"type":"mark","name":"lsp.code_action","count":16,"args":{"textDocument":{"uri":"file:https:///Users/ib/dev/apps/decohub/apps/linx.ts"},"range":{"start":{"line":16,"character":7},"end":{"line":16,"character":7}},"context":{"diagnostics":[],"triggerKind":2}}},
{"type":"mark","name":"tsc.request.getApplicableRefactors"},
{"type":"mark","name":"tsc.host.getApplicableRefactors","count":11,"args":["file:https:///Users/ib/dev/apps/decohub/apps/linx.ts",{"pos":375,"end":375},{"quotePreference":"double","includeCompletionsForModuleExports":true,"includeCompletionsForImportStatements":true,"includeCompletionsWithSnippetText":true,"includeAutomaticOptionalChainCompletions":true,"includeCompletionsWithInsertText":true,"includeCompletionsWithClassMemberSnippets":true,"includeCompletionsWithObjectLiteralMethodSnippets":true,"useLabelDetailsInCompletionEntries":true,"allowIncompleteCompletions":true,"importModuleSpecifierPreference":"shortest","importModuleSpecifierEnding":"index","allowTextChangesInNewFiles":true,"providePrefixAndSuffixTextForRename":true,"provideRefactorNotApplicableReason":true,"jsxAttributeCompletionStyle":"auto","includeInlayParameterNameHints":"all","includeInlayParameterNameHintsWhenArgumentMatchesName":false,"includeInlayFunctionParameterTypeHints":true,"includeInlayVariableTypeHints":true,"includeInlayVariableTypeHintsWhenTypeMatchesName":false,"includeInlayPropertyDeclarationTypeHints":true,"includeInlayFunctionLikeReturnTypeHints":true,"includeInlayEnumMemberValueHints":true,"autoImportFileExcludePatterns":[]},null,""]},
{"type":"measure","name":"tsc.request.getApplicableRefactors","count":16,"duration":21.72},
Failed to request to tsserver TypeError: Cannot read properties of undefined (reading 'kind')
    at isVariableDeclaration (ext:deno_tsc/00_typescript.js:26883:17)
    at isSingleVariableDeclaration (ext:deno_tsc/00_typescript.js:140911:12)
    at tryGetFunctionFromVariableDeclaration (ext:deno_tsc/00_typescript.js:140914:10)
    at getFunctionInfo (ext:deno_tsc/00_typescript.js:140898:18)
    at Object.getRefactorActionsToConvertFunctionExpressions [as getAvailableActions] (ext:deno_tsc/00_typescript.js:140819:18)
    at ext:deno_tsc/00_typescript.js:138302:224
    at flatMapIterator (ext:deno_tsc/00_typescript.js:333:21)
    at flatMapIterator.next (<anonymous>)
    at arrayFrom (ext:deno_tsc/00_typescript.js:870:16)
    at Object.getApplicableRefactors (ext:deno_tsc/00_typescript.js:138300:12)
[Error - 21:14:46] Request textDocument/codeAction failed.
  Message: Invalid request
  Code: -32600 

@nathanwhit nathanwhit force-pushed the lsp-granular-js-cache-eviction branch from 1a2409a to 63f1eec Compare April 10, 2024 20:13
@nathanwhit nathanwhit force-pushed the lsp-granular-js-cache-eviction branch from 63f1eec to 4588ca6 Compare April 10, 2024 20:16
Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I profiled this again and can definitely see an improvement 👍

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Great work!

Copy link
Collaborator

@nayeemrmn nayeemrmn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@nathanwhit nathanwhit merged commit 736f73b into denoland:main Apr 11, 2024
17 checks passed
@nathanwhit nathanwhit deleted the lsp-granular-js-cache-eviction branch April 11, 2024 01:07
satyarohith pushed a commit that referenced this pull request Apr 11, 2024
…23293)

Currently we evict a lot of the caches on the JS side of things on every
request, namely script versions, script file names, and compiler
settings (as of #23283, it's not quite every request but it's still
unnecessarily often).

This PR reports changes to the JS side, so that it can evict exactly the
caches that it needs too. We might want to do some batching in the
future so as not to do 1 request per change.
@ceifa
Copy link

ceifa commented Apr 11, 2024

I can no longer see op_script_version op calls in the profile (createProgram goes from 50ms to 10ms), however I get these errors:

Failed to request to tsserver TypeError: Cannot read properties of undefined (reading 'kind')
    at isVariableDeclaration (ext:deno_tsc/00_typescript.js:26883:17)
    at isSingleVariableDeclaration (ext:deno_tsc/00_typescript.js:140911:12)
    at tryGetFunctionFromVariableDeclaration (ext:deno_tsc/00_typescript.js:140914:10)
    at getFunctionInfo (ext:deno_tsc/00_typescript.js:140898:18)
    at Object.getRefactorActionsToConvertFunctionExpressions [as getAvailableActions] (ext:deno_tsc/00_typescript.js:140819:18)
    at ext:deno_tsc/00_typescript.js:138302:224
    at flatMapIterator (ext:deno_tsc/00_typescript.js:333:21)
    at flatMapIterator.next (<anonymous>)
    at arrayFrom (ext:deno_tsc/00_typescript.js:870:16)
    at Object.getApplicableRefactors (ext:deno_tsc/00_typescript.js:138300:12)
[Error - 21:14:39] Request textDocument/codeAction failed.
  Message: Invalid request
  Code: -32600 
{"type":"mark","name":"lsp.code_lens","count":10,"args":{"textDocument":{"uri":"file:https:///Users/ib/dev/apps/decohub/apps/linx.ts"}}},
{"type":"measure","name":"lsp.code_lens","count":10,"duration":0.004},
{"type":"mark","name":"lsp.code_action","count":16,"args":{"textDocument":{"uri":"file:https:///Users/ib/dev/apps/decohub/apps/linx.ts"},"range":{"start":{"line":16,"character":7},"end":{"line":16,"character":7}},"context":{"diagnostics":[],"triggerKind":2}}},
{"type":"mark","name":"tsc.request.getApplicableRefactors"},
{"type":"mark","name":"tsc.host.getApplicableRefactors","count":11,"args":["file:https:///Users/ib/dev/apps/decohub/apps/linx.ts",{"pos":375,"end":375},{"quotePreference":"double","includeCompletionsForModuleExports":true,"includeCompletionsForImportStatements":true,"includeCompletionsWithSnippetText":true,"includeAutomaticOptionalChainCompletions":true,"includeCompletionsWithInsertText":true,"includeCompletionsWithClassMemberSnippets":true,"includeCompletionsWithObjectLiteralMethodSnippets":true,"useLabelDetailsInCompletionEntries":true,"allowIncompleteCompletions":true,"importModuleSpecifierPreference":"shortest","importModuleSpecifierEnding":"index","allowTextChangesInNewFiles":true,"providePrefixAndSuffixTextForRename":true,"provideRefactorNotApplicableReason":true,"jsxAttributeCompletionStyle":"auto","includeInlayParameterNameHints":"all","includeInlayParameterNameHintsWhenArgumentMatchesName":false,"includeInlayFunctionParameterTypeHints":true,"includeInlayVariableTypeHints":true,"includeInlayVariableTypeHintsWhenTypeMatchesName":false,"includeInlayPropertyDeclarationTypeHints":true,"includeInlayFunctionLikeReturnTypeHints":true,"includeInlayEnumMemberValueHints":true,"autoImportFileExcludePatterns":[]},null,""]},
{"type":"measure","name":"tsc.request.getApplicableRefactors","count":16,"duration":21.72},
Failed to request to tsserver TypeError: Cannot read properties of undefined (reading 'kind')
    at isVariableDeclaration (ext:deno_tsc/00_typescript.js:26883:17)
    at isSingleVariableDeclaration (ext:deno_tsc/00_typescript.js:140911:12)
    at tryGetFunctionFromVariableDeclaration (ext:deno_tsc/00_typescript.js:140914:10)
    at getFunctionInfo (ext:deno_tsc/00_typescript.js:140898:18)
    at Object.getRefactorActionsToConvertFunctionExpressions [as getAvailableActions] (ext:deno_tsc/00_typescript.js:140819:18)
    at ext:deno_tsc/00_typescript.js:138302:224
    at flatMapIterator (ext:deno_tsc/00_typescript.js:333:21)
    at flatMapIterator.next (<anonymous>)
    at arrayFrom (ext:deno_tsc/00_typescript.js:870:16)
    at Object.getApplicableRefactors (ext:deno_tsc/00_typescript.js:138300:12)
[Error - 21:14:46] Request textDocument/codeAction failed.
  Message: Invalid request
  Code: -32600 

Just got the exactly same error on VSCode output (also the types is not working correctly):

image

deno 1.42.2 (release, x86_64-pc-windows-msvc)
v8 12.3.219.9
typescript 5.4.3

@ceifa
Copy link

ceifa commented Apr 11, 2024

Fixed after downgrading to 1.42.0

@bartlomieju
Copy link
Member

@ceifa do you only get these errors in Jupyter notebook or when editing regular files as well?

nathanwhit added a commit that referenced this pull request Apr 11, 2024
…3322)

Fixes the regression described in
#23293 (comment).
This affected jupyter notebooks, as the LSP was passing in already
denormalized specifiers, while the jupyter kernel was not. We need to
denormalize the specifiers to evict the proper keys from our caches.
@bartlomieju
Copy link
Member

@ceifa the problem should be fixed now and will be released in Deno v1.42.3.

@ceifa
Copy link

ceifa commented Apr 11, 2024

Thanks!

bartlomieju pushed a commit that referenced this pull request Apr 12, 2024
…3322)

Fixes the regression described in
#23293 (comment).
This affected jupyter notebooks, as the LSP was passing in already
denormalized specifiers, while the jupyter kernel was not. We need to
denormalize the specifiers to evict the proper keys from our caches.
littledivy pushed a commit to littledivy/deno that referenced this pull request Apr 19, 2024
…enoland#23293)

Currently we evict a lot of the caches on the JS side of things on every
request, namely script versions, script file names, and compiler
settings (as of denoland#23283, it's not quite every request but it's still
unnecessarily often).

This PR reports changes to the JS side, so that it can evict exactly the
caches that it needs too. We might want to do some batching in the
future so as not to do 1 request per change.
littledivy pushed a commit to littledivy/deno that referenced this pull request Apr 19, 2024
…noland#23322)

Fixes the regression described in
denoland#23293 (comment).
This affected jupyter notebooks, as the LSP was passing in already
denormalized specifiers, while the jupyter kernel was not. We need to
denormalize the specifiers to evict the proper keys from our caches.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants