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

Keystroke lag in TypeScript #7415

Open
Cre3per opened this issue Jan 22, 2022 · 5 comments
Open

Keystroke lag in TypeScript #7415

Cre3per opened this issue Jan 22, 2022 · 5 comments

Comments

@Cre3per
Copy link

Cre3per commented Jan 22, 2022

Describe the bug
Noticeable keystroke lag when typing in TypeScript files.
Only observed when NativeScript is installed. I don't have issues with other TypeScript projects. Likely caused by many/large .d.ts files.

Ways to stop the lag

  • Disable VSCodeVim
  • Disable editor.quickSuggestions (This is my best workaround so far)
  • Change the language mode to a non-TypeScript language

To Reproduce
Steps to reproduce the behavior:

  1. In an empty directory
npm init -y
npm install "@nativescript/types"
touch tsconfig.json
echo '/// <reference path="./node_modules/@nativescript/types/index.d.ts" />' > references.d.ts
  1. Open the project in vscode
  2. Open index.ts
  3. Wait for "Initializing JS/TS language features" in bottom bar to disappear (takes ~1 second)
  4. Type "console"

Alternatively, after the file has been opened and js/ts initialized

  1. Press ctrl+space to trigger auto-complete
  2. Type (Will be delayed until auto-complete finished loading suggestions)

Expected behavior
Typing is smooth and snappy. There are no noticeable delays after pressing a key

Environment (please complete the following information):

  • Extension (VsCodeVim) version: 1.21.10
  • VSCode version: 1.63.2
  • OS: 5.16.2-arch1-1 x86_64 GNU/Linux

All non-default extensions are disabled.

Additional context
Developer Tools Log while typing the letters "le" of "console" (handleKeyEvent() takes >100ms). The slower I type the earlier the slow keystroke occurs. The written word and letters don't matter.

[Extension Host] ModeHandler: debug: handling key=l.
console.ts:137 [Extension Host] Remapper: debug: trying to find matching remap. keys=l. mode=Insert. keybindings=insertModeKeyBindingsMap.
console.ts:137 [Extension Host] Transformer: debug: Adding Transformation {"type":"insertTextVSCode","text":"l","isMultiCursor":false}
console.ts:137 [Extension Host] Extension Startup: debug: Selections: ignoring intermediate selection change: [0, 6; 0, 6]
console.ts:137 [Extension Host] ModeHandler: debug: handleKeyEvent('l') took 211ms
console.ts:137 [Extension Host] ModeHandler: debug: handling key=e.
console.ts:137 [Extension Host] Remapper: debug: trying to find matching remap. keys=e. mode=Insert. keybindings=insertModeKeyBindingsMap.
console.ts:137 [Extension Host] Transformer: debug: Adding Transformation {"type":"insertTextVSCode","text":"e","isMultiCursor":false}
console.ts:137 [Extension Host] Extension Startup: debug: Selections: ignoring intermediate selection change: [0, 7; 0, 7]
console.ts:137 [Extension Host] ModeHandler: debug: handleKeyEvent('e') took 31ms

I have traced the lag down to execute.ts executeTransformations()

      case 'insertTextVSCode':
        const now = Number(new Date());
        await TextEditor.insert(vimState.editor, transformation.text);
        console.log(`insertion took ${Number(new Date()) - now}ms`);
        vimState.cursors[0] = Cursor.FromVSCodeSelection(vimState.editor.selection);
        break;

Thanks for the awesome extension, it has served me well so far!

@Cre3per
Copy link
Author

Cre3per commented Jan 22, 2022

Likely related to microsoft/vscode#65876

@Cre3per
Copy link
Author

Cre3per commented Jan 22, 2022

I have the same issue with the minimal extension shown by alex here microsoft/vscode#65876 (comment)

Removing

  • await when calling TextEditor.insert
  • The line vimState.cursors[0] = Cursor.FromVSCodeSelection(vimState.editor.selection); in execute.ts executeTransformations()

reduces the handleKeyEvent() duration to normal 5ms, but doesn't solve the issue. This hints that using a command other than default:type (If one exists) will not solve the issue.

My current guess is that default:type triggers "something" (Autocomplete) and awaits it.
If we don't await default:type, "something" will be awaited by another command later.

@Cre3per
Copy link
Author

Cre3per commented Jan 22, 2022

VSCode Neovim bypasses this issue by disposing its "type" command handler when entering insert mode. They register a keybind on "escape", "ctrl+[", and "ctrl+c" to return to normal mode and re-register the "type" handler.
While recording, they keep the "type" handler attached but don't use "default:type". I didn't see how they update the editor while recording. IIRC vimState.editor.edit(TextEdit.insert(/* ... */)) can be used to update the editor without triggering suggestions (Thus causing no lag).

I'm a vim newbie, I don't know if keystrokes in insert mode are needed for anything other than recording*. Maybe someone more experienced can get me up to speed.
Is there a reason why VSCodeVim can't behave like this?

Looking into these extensions has been pleasant so far. If I get confirmation that VSCodeVim could replicate VSCode Neovim's behavior, I'd like to try fixing VSCodeVim.

*UPDATE: ctrl+k and ctrl+v for digraphs and unicode. Might be doable with keybinds. The neovim extension doesn't support these.

@Arcitec
Copy link

Arcitec commented Jan 31, 2023

Looks like a good investigation. Thanks @Cre3per. I decided to switch to the NeoVim extension for the reasons outlined by you and summarized by me here:

#8115 (comment)

It's also a more complete Vim implementation because it's literally Vim, not an emulation.

If the extreme slowdown in VSCode/VSCodeVim is ever solved, I'll probably switch back since the idea of having Vim entirely implemented in JavaScript appeals to me.

@Ahmad-Alkaf
Copy link

Ways to stop the lag

  • Disable VSCodeVim
  • Disable editor.quickSuggestions (This is my best workaround so far)
  • Change the language mode to a non-TypeScript language

@Cre3per I noticed also delaying the quick suggestions pop-up editor.quickSuggestionsDelay to about 600 stopped the lagging

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

No branches or pull requests

3 participants