Keystroke lag in TypeScript
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 15.2k
- Forks
- 1.5k
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 6
Description
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:
- 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
- Open the project in vscode
- Open index.ts
- Wait for "Initializing JS/TS language features" in bottom bar to disappear (takes ~1 second)
- Type "console"
Alternatively, after the file has been opened and js/ts initialized
- Press ctrl+space to trigger auto-complete
- 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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the lag with the NativeScript types setup and the listed VS Code and VSCodeVim versions. Start in execute.ts at executeTransformations(), especially the insertTextVSCode path and TextEditor.insert call, and compare the timing logs while typing or triggering completion. Done means the reproduction no longer causes noticeable keystroke delays without disabling TypeScript features.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vscode
- Domain
- performance, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100