vscode: Code freezes when it receives focus
Issue Type: Performance Issue
The issue itself is very simple to explain: When VSCode is already up and running and I switch the focus to anonther application (e.g. Browser, File Explorer, …) and then after some time (>~5s) switch focus back to VSCode, the window just freezes for 1-3s before everything is back to normal.
Has happened to me consistently over the last 6 months at least, happened in each and every project.
It is something that is unfortunately not reliable to reproduce. Sometimes I can code a few hours or days, before it hits me, but sometimes it happens very frequent as well.
Only solution right now is to completely restart all VSCode instances.
I did a performance recording as suggested here, and uploaded it to this issue here: vscode-pprof.json.txt
The bug is not related to extensions, since I reproduced it while all extensions were disabled
VS Code version: Code - OSS 1.68.1 (30d9c6cd9483b2cc586687151bcbcd635f373630, 2022-06-16T08:22:04.269Z) OS version: Linux x64 5.15.50-1-lts Restricted Mode: No
System Info
Item | Value |
---|---|
CPUs | AMD Ryzen 7 4800U with Radeon Graphics (16 x 1800) |
GPU Status | 2d_canvas: enabled canvas_oop_rasterization: disabled_off direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on oop_rasterization: disabled_off opengl: enabled_on rasterization: disabled_software raw_draw: disabled_off_ok skia_renderer: enabled_on video_decode: disabled_software video_encode: disabled_software vulkan: disabled_off webgl: enabled webgl2: enabled |
Load (avg) | 3, 2, 2 |
Memory (System) | 15.00GB (1.28GB free) |
Process Argv | –unity-launch |
Screen Reader | no |
VM | 0% |
DESKTOP_SESSION | undefined |
XDG_CURRENT_DESKTOP | undefined |
XDG_SESSION_DESKTOP | undefined |
XDG_SESSION_TYPE | wayland |
Process Info
CPU % Mem MB PID Process
0 200 5727 code-oss main
0 77 5730 zygote
0 200 5756 gpu-process
0 77 5731 zygote
0 0 5733 zygote
0 31 37896 utility
0 108 38912 issue-reporter
0 92 5791 utility-network-service
0 261 5804 window (backend.go - vision - Code - OSS)
3 277 5805 window (daemon.go - nline - Code - OSS)
0 277 5811 window (semanticsegmentationmodel_test.go - nlib - Code - OSS)
0 169 5896 shared-process
0 108 5975 ptyHost
0 0 7243 /usr/bin/bash
0 0 7262 /usr/bin/bash
0 0 7333 /usr/bin/bash
0 0 14638 /usr/bin/bash
0 92 6016 fileWatcher
0 92 6017 fileWatcher
0 92 14598 fileWatcher
0 92 38171 fileWatcher
0 0 38930 /usr/bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command=
0 154 5897 extensionHost
0 184 6146 /home/skaldesh/go/bin/gopls -mode=stdio
0 154 5934 extensionHost
0 246 6420 /home/skaldesh/go/bin/gopls -mode=stdio
0 292 14514 window (camera.go - camera - Code - OSS)
0 154 14586 extensionHost
0 230 14684 /home/skaldesh/go/bin/gopls -mode=stdio
1 138 38158 extensionHost
0 277 38435 /home/skaldesh/go/bin/gopls -mode=stdio
Workspace Info
| Window (camera.go - camera - Code - OSS)
| Window (semanticsegmentationmodel_test.go - nlib - Code - OSS)
| Window (daemon.go - nline - Code - OSS)
| Window (backend.go - vision - Code - OSS)
| Folder (camera): 811 files
| File types: go(79) h(24) cpp(21) yaml(4) md(2) gitignore(1) pprof(1)
| tar(1) txt(1) mod(1)
| Conf files:
| Folder (nline): 1520 files
| File types: go(64) xml(8) md(2) npack(2) yaml(2) gitignore(1) iml(1)
| json(1) tar(1) txt(1)
| Conf files: settings.json(1) dockerfile(1)
| Folder (nlib): 6451 files
| File types: jpg(5030) go(82) yaml(41) npack(30) h(25) cpp(22) xml(12)
| onnx(12) md(9) pt(9)
| Conf files: launch.json(1)
| Launch Configs: go
| Folder (vision): 3619 files
| File types: qml(578) png(182) qmlc(170) dll(106) o(51) qmltypes(39)
| cpp(24) h(18) js(13) go(12)
| Conf files: makefile(3);
Extensions (8)
Extension | Author (truncated) | Version |
---|---|---|
systemd-unit-file | coo | 1.0.6 |
dart-code | Dar | 3.44.0 |
go | gol | 0.34.1 |
vscode-simple-icons | Lau | 1.16.0 |
hexeditor | ms- | 1.9.7 |
orbit | r0l | 0.0.1 |
cmake | twx | 0.0.17 |
vscode-todo-highlight | way | 1.0.5 |
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 29 (1 by maintainers)
There actually is an easier workaround. The program files themselves aren’t an issue in any capacity so there is no need to reinstall Code. Deleting the entirety of
%AppData%\Code
means you lose all workspaces you have to configure again and again. What I tried was more of a drastic “I need to find a solution now” trial and error. While it did work, https://github.com/microsoft/vscode/issues/146737#issuecomment-1153131501 made an excellent point. I completely forgot to revisit this topic but since I have been mentioned here, I’ll leave this bit of information.Close Code and simply delete the following directories:
Code lacks a method to clear all caches. The user must manually do so to restore expected performance.
@skaldesh You have to clear the VSCode cache, as I described here https://github.com/microsoft/vscode/issues/146737#issuecomment-1153128058 The slowness/freezing is caused by large amounts of cached files compounding and giving sluggish performance after some time. The only solution I have found was to completely uninstall, remove the cache folders and reinstall VSCode. You already know all of this, but unfortunately we cannot continue commenting in that issue https://github.com/microsoft/vscode/issues/146737 because for some reason someone locked it up.
Anyway, you should have mentioned that issue here and also my response, even if it annoys you having to clean the cache. You want to find another, easier solution, without having to reinstall VSCode, I get it. But believe me, you won’t find any. I’ve been pulling out my hair for many months until I nuked everything and started fresh.
For further info, I’ll post my response from https://github.com/microsoft/vscode/issues/146737 here as well, since that issue is locked:
The solution to get rid of the slowness and get back the snappiness and quick reaction when focusing back to VSCode from another program is to uninstall VSCode, restart the PC and completely remove the folder
C:\Users\[User]\AppData\Roaming\Code
, which in my case had 380 MB and several thousand files cached in it. The folder has grown so much over 2 years of daily VSCode use, with regular upgrading to newest version as soon as it was released. I’ve also removed the VSCode extensions folderC:\Users\[User]\.vscode
, I’m not sure whether that helped or not.After reinstalling VSCode I had to reconfigure everything from scratch and install all extensions, but the cache folder is now only 80 MB and contains 550 files. Working with VSCode is a breeze again…
*Credit goes to @icedterminal https://github.com/microsoft/vscode/issues/146737#issuecomment-1124494187 - thanks for the idea!
*Cross-referencing possibly related issues, perhaps it helps someone else not noticing this solution: https://github.com/microsoft/vscode/issues/123257 https://github.com/microsoft/vscode/issues/141735 https://github.com/microsoft/vscode/issues/147151 https://github.com/microsoft/vscode/issues/147188
Edit: Slow file open fixed as well - brilliant!