microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.91k stars 29.17k forks source link

Untitled CSV file is being recognized as Python file, causing high CPU usage #232514

Closed blacelle closed 1 day ago

blacelle commented 1 week ago

Environment data

Code Snippet

No python code, as the issue seems unrelated to .py files.

Repro Steps

  1. Unclear reproduction scenario
  2. It seems related to having a large (5MB) CSV file open, next to some casual single .py file
  3. It may be related to some Unsaved file holding the CSV content.
  4. It seemed indeed reproduced after open a new tab, and copying into it 200k rows of lines holding around 30 chars.

Expected behavior

Low CPU activity

Actual behavior

100% single-thread activity for minutes.

Closing the Unsaved tab should kill the faulty process, but it remains 100% CPU. I need to kill it. Killing while having the tab still open let another process starting right away with 100% activity.

Logs

2024-10-23 10:09:17.805 [info] (57192) [FG] parsing: untitled:Untitled-2 (1770ms)
2024-10-23 10:09:30.124 [info] [Error - 10:09:30] Server process exited with signal SIGKILL.
2024-10-23 10:09:30.128 [info] [Info  - 10:09:30] Connection to server got closed. Server will restart.
2024-10-23 10:09:30.128 [info] true
2024-10-23 10:09:30.821 [info] [Info  - 10:09:30] (57585) Server root directory: file:///Users/blacelle/.vscode/extensions/ms-python.vscode-pylance-2024.10.1/dist
2024-10-23 10:09:30.822 [info] [Info  - 10:09:30] (57585) Pylance language server 2024.10.1 (pyright version 1.1.382, commit e46efc6b) starting
2024-10-23 10:09:30.828 [info] [Info  - 10:09:30] (57585) Starting service instance "lerobot"
2024-10-23 10:09:30.929 [info] (57585) No configuration file found.
2024-10-23 10:09:30.929 [info] (57585) No pyproject.toml file found.
2024-10-23 10:09:30.929 [info] [Info  - 10:09:30] (57585) Setting environmentName for service "lerobot": "3.12.4 (.venv venv)"
2024-10-23 10:09:30.929 [info] [Info  - 10:09:30] (57585) Setting pythonPath for service "lerobot": "/Users/blacelle/workspace3/domains/src/main/resources/lerobot/.venv/bin/python"
2024-10-23 10:09:30.930 [info] [Info  - 10:09:30] (57585) No include entries specified; assuming /Users/blacelle/workspace3/domains/src/main/resources/lerobot
2024-10-23 10:09:30.930 [info] [Info  - 10:09:30] (57585) Auto-excluding **/node_modules
2024-10-23 10:09:30.931 [info] [Info  - 10:09:30] (57585) Auto-excluding **/__pycache__
2024-10-23 10:09:30.931 [info] [Info  - 10:09:30] (57585) Auto-excluding **/.*
2024-10-23 10:09:30.980 [info] [Info  - 10:09:30] (57585) Assuming Python version 3.12.4.final.0
2024-10-23 10:09:30.980 [info] (57585) Assuming Python platform Darwin
2024-10-23 10:09:31.066 [info] [Info  - 10:09:31] (57585) Execution environment: 3.12.4 (.venv venv)
2024-10-23 10:09:31.066 [info] [Info  - 10:09:31] (57585)   Extra paths:
2024-10-23 10:09:31.067 [info] [Info  - 10:09:31] (57585)     (none)
2024-10-23 10:09:31.067 [info] [Info  - 10:09:31] (57585)   Python version: 3.12.4.final.0
2024-10-23 10:09:31.067 [info] [Info  - 10:09:31] (57585)   Python platform: Darwin
2024-10-23 10:09:31.067 [info] [Info  - 10:09:31] (57585)   Search paths:
2024-10-23 10:09:31.067 [info] [Info  - 10:09:31] (57585)     /Users/blacelle/.vscode/extensions/ms-python.vscode-pylance-2024.10.1/dist/typeshed-fallback/stdlib
2024-10-23 10:09:31.068 [info] [Info  - 10:09:31] (57585)     /Users/blacelle/workspace3/domains/src/main/resources/lerobot
2024-10-23 10:09:31.068 [info] [Info  - 10:09:31] (57585)     /Users/blacelle/workspace3/domains/src/main/resources/lerobot/typings
2024-10-23 10:09:31.068 [info] [Info  - 10:09:31] (57585)     /Users/blacelle/.vscode/extensions/ms-python.vscode-pylance-2024.10.1/dist/typeshed-fallback/stubs/...
2024-10-23 10:09:31.069 [info] [Info  - 10:09:31] (57585)     /Users/blacelle/.vscode/extensions/ms-python.vscode-pylance-2024.10.1/dist/bundled/stubs
2024-10-23 10:09:31.069 [info] [Info  - 10:09:31] (57585)     /usr/local/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12
2024-10-23 10:09:31.069 [info] [Info  - 10:09:31] (57585)     /usr/local/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/lib-dynload
2024-10-23 10:09:31.069 [info] [Info  - 10:09:31] (57585)     /Users/blacelle/workspace3/domains/src/main/resources/lerobot/.venv/lib/python3.12/site-packages
2024-10-23 10:09:31.069 [info] [Info  - 10:09:31] (57585) Execution environment: 3.12.4 (.venv venv)
2024-10-23 10:09:31.070 [info] [Info  - 10:09:31] (57585)   Extra paths:
2024-10-23 10:09:31.070 [info] [Info  - 10:09:31] (57585)     (none)
2024-10-23 10:09:31.070 [info] [Info  - 10:09:31] (57585)   Python version: 3.12.4.final.0
2024-10-23 10:09:31.070 [info] [Info  - 10:09:31] (57585)   Python platform: Darwin
2024-10-23 10:09:31.070 [info] [Info  - 10:09:31] (57585)   Search paths:
2024-10-23 10:09:31.070 [info] [Info  - 10:09:31] (57585)     /Users/blacelle/.vscode/extensions/ms-python.vscode-pylance-2024.10.1/dist/typeshed-fallback/stdlib
2024-10-23 10:09:31.070 [info] [Info  - 10:09:31] (57585)     /Users/blacelle/workspace3/domains/src/main/resources/lerobot
2024-10-23 10:09:31.071 [info] [Info  - 10:09:31] (57585)     /Users/blacelle/workspace3/domains/src/main/resources/lerobot/typings
2024-10-23 10:09:31.071 [info] [Info  - 10:09:31] (57585)     /Users/blacelle/.vscode/extensions/ms-python.vscode-pylance-2024.10.1/dist/typeshed-fallback/stubs/...
2024-10-23 10:09:31.071 [info] [Info  - 10:09:31] (57585)     /Users/blacelle/.vscode/extensions/ms-python.vscode-pylance-2024.10.1/dist/bundled/stubs
2024-10-23 10:09:31.071 [info] [Info  - 10:09:31] (57585)     /usr/local/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12
2024-10-23 10:09:31.071 [info] [Info  - 10:09:31] (57585)     /usr/local/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/lib-dynload
2024-10-23 10:09:31.071 [info] [Info  - 10:09:31] (57585)     /Users/blacelle/workspace3/domains/src/main/resources/lerobot/.venv/lib/python3.12/site-packages
2024-10-23 10:09:31.071 [info] [Info  - 10:09:31] (57585) Adding fs watcher for library directories:
 file:///usr/local/Cellar/python%403.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12
file:///Users/blacelle/workspace3/domains/src/main/resources/lerobot/.venv/lib/python3.12/site-packages
2024-10-23 10:09:31.071 [info] [Info  - 10:09:31] (57585) Adding fs watcher for directories:
 file:///Users/blacelle/workspace3/domains/src/main/resources/lerobot
2024-10-23 10:09:31.072 [info] (57585) Searching for source files
2024-10-23 10:09:31.072 [info] [Info  - 10:09:31] (57585) Auto-excluding /Users/blacelle/workspace3/domains/src/main/resources/lerobot/source
2024-10-23 10:09:31.072 [info] [Info  - 10:09:31] (57585) Found 1 source file
2024-10-23 10:09:31.087 [info] (57585) pytest configurations: {"message":"request cancelled","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2024-10-23 10:09:31.151 [info] (57585) pytest configurations: {"message":"script","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2024-10-23 10:09:32.553 [info] (57585) [FG] parsing: untitled:Untitled-2 (1400ms)
2024-10-23 10:09:32.594 [info] (57585) [FG] parsing: file:///Users/blacelle/.vscode/extensions/ms-python.vscode-pylance-2024.10.1/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 0ms] (40ms)
2024-10-23 10:09:32.624 [info] (57585) [FG] binding: file:///Users/blacelle/.vscode/extensions/ms-python.vscode-pylance-2024.10.1/dist/typeshed-fallback/stdlib/builtins.pyi (29ms)

I added python.analysis.logLevek: Trace and set Trace in the Toggle in the output. Though, I feel Traces are not reported. Still, we see 2024-10-23 10:09:32.553 [info] (57585) [FG] parsing: untitled:Untitled-2 (1400ms) which rfers to my large unsaved CSV file.

I keep seeing in ps aux | grep python the faulty process:

57585 98.4 0.6 1224960064 430896 ?? R 10:09AM 2:01.17 /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) /Users/blacelle/.vscode/extensions/ms-python.vscode-pylance-2024.10.1/dist/server.bundle.js --cancellationReceive=file:2c4d3c60fe5ebaea679e274e533fdcba10859ffc44 --node-ipc --clientProcessId=24765

StellaHuang95 commented 1 week ago

Could you share what file type is displayed in the status bar at the bottom right corner when you open the untitled file? Trying to understand if VS Code is treating the cvs file as a Python file. Also, does that repro if you save the file?

Image

blacelle commented 1 week ago

Image It is assumed as Python.

Image Once saved, and the environment reloaded, the file is properly detected as CSV and the issue does not appear.

StellaHuang95 commented 1 week ago

This might be an issue with VSCode's content-based language detection system that analyzes the content of the untitled file and attempts to guess the appropriate language mode. Transferring to vscode.

TylerLeonhardt commented 1 day ago

Just to be clear, a CSV being guessed as Python is an issue, but any content causing a CPU spike when it's in a Python file is a separate Pylance issue.

As a user, I can manually switch the language, if I accidentally pick Python, and suddenly my machine crawls, that's an issue in the language server.

TylerLeonhardt commented 1 day ago

Linking this with the meta issue of samples where our model chooses the wrong language: https://github.com/microsoft/vscode/issues/131450