Python formatting very slow in Dev Container
See original GitHub issueIssue Type: Bug
Behaviour
Expected vs. Actual
Expected:
- Fast to save a file with ‘formatOnSave’ set to true inside a dev container
Actual:
- takes ~6 seconds to sort imports and then format code
- Note: that it seems to be fast outside of a dev container
- Note: This seems to have regressed with build
2022.01786462952
. The build before it,2021.12.1559732655
does not have this issue. The latest build, 2022.0.1814523869, still has this issue.
Steps to reproduce:
- Create a Dockerfile that:
- Installs an editable poetry package
- Here is the list of dev dependencies in
pyproject.toml
:
[tool.poetry.dev-dependencies]
bandit = "^1.7.1"
black = "^21.11b0"
flake8 = "^4.0.1"
isort = "^5.10.1"
markdown = "3.3.4"
pytest = "^5.2"
pytest-mock = "^3.6.1"
mkdocs = "^1.2.3"
mkdocstrings = "^0.16.2"
ipykernel = "^6.6.0"
pytest-recording = "^0.12.0"
- Create a devcontainer.json like this:
"settings": {
// Resolve import errors in Jupyter / ipython
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[python]": {
"editor.tabSize": 4
},
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"editor.formatOnSave": true,
"editor.tabSize": 2,
"python.analysis.extraPaths": ["sdk"],
"python.defaultInterpreterPath": "/opt/conda/bin/python",
"python.formatting.provider": "black",
"python.linting.banditEnabled": true,
"python.linting.flake8Enabled": true,
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"terminal.integrated.inheritEnv": false
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"amodio.toggle-excluded-files",
"bierner.markdown-emoji",
"esbenp.prettier-vscode",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-toolsai.jupyter",
"tamasfe.even-better-toml",
"timonwong.shellcheck",
"yzhang.markdown-all-in-one"
]
Diagnostic data
- Python version (& distribution if applicable, e.g. Anaconda): 3.9.7
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
- Value of the
python.languageServer
setting: Default
User Settings
defaultLS: {"defaultLSType":"Pylance"}
downloadLanguageServer: true
envFile: "<placeholder>"
venvPath: "<placeholder>"
venvFolders: "<placeholder>"
condaPath: "<placeholder>"
pipenvPath: "<placeholder>"
poetryPath: "<placeholder>"
languageServer: "Pylance"
linting
• enabled: true
• cwd: "<placeholder>"
• Flake8Args: "<placeholder>"
• flake8Enabled: true
• flake8Path: "<placeholder>"
• lintOnSave: true
• banditArgs: "<placeholder>"
• banditEnabled: true
• banditPath: "<placeholder>"
• mypyArgs: "<placeholder>"
• mypyEnabled: false
• mypyPath: "<placeholder>"
• pycodestyleArgs: "<placeholder>"
• pycodestyleEnabled: false
• pycodestylePath: "<placeholder>"
• prospectorArgs: "<placeholder>"
• prospectorEnabled: false
• prospectorPath: "<placeholder>"
• pydocstyleArgs: "<placeholder>"
• pydocstyleEnabled: false
• pydocstylePath: "<placeholder>"
• pylamaArgs: "<placeholder>"
• pylamaEnabled: false
• pylamaPath: "<placeholder>"
• pylintArgs: "<placeholder>"
• pylintPath: "<placeholder>"
sortImports
• args: "<placeholder>"
• path: "<placeholder>"
formatting
• autopep8Args: "<placeholder>"
• autopep8Path: "<placeholder>"
• provider: "black"
• blackArgs: "<placeholder>"
• blackPath: "<placeholder>"
• yapfArgs: "<placeholder>"
• yapfPath: "<placeholder>"
testing
• cwd: "<placeholder>"
• debugPort: 3000
• nosetestArgs: "<placeholder>"
• nosetestsEnabled: undefined
• nosetestPath: "<placeholder>"
• promptToConfigure: true
• pytestArgs: "<placeholder>"
• pytestEnabled: true
• pytestPath: "<placeholder>"
• unittestArgs: "<placeholder>"
• unittestEnabled: false
• autoTestDiscoverOnSaveEnabled: true
terminal
• activateEnvironment: true
• executeInFileDir: "<placeholder>"
• launchArgs: "<placeholder>"
experiments
• enabled: true
• optInto: []
• optOutFrom: []
insidersChannel: "off"
tensorBoard
• logDirectory: "<placeholder>"
Extension version: 2022.0.1814523869 VS Code version: Code 1.64.1 (d6ee99e4c045a6716e5c653d7da8e9ae6f5a8b03, 2022-02-07T17:26:08.977Z) OS version: Darwin x64 20.6.0 Restricted Mode: No Remote OS version: Linux x64 5.10.76-linuxkit
System Info
Item | Value |
---|---|
CPUs | Intel® Core™ i9-9980HK CPU @ 2.40GHz (16 x 2400) |
GPU Status | 2d_canvas: enabled gpu_compositing: enabled metal: disabled_off multiple_raster_threads: enabled_on oop_rasterization: enabled opengl: enabled_on rasterization: enabled skia_renderer: disabled_off_ok video_decode: enabled webgl: enabled webgl2: enabled |
Load (avg) | 6, 4, 3 |
Memory (System) | 32.00GB (0.20GB free) |
Process Argv | –crash-reporter-id 4758608f-d190-4905-8b7b-9580cf264aef |
Screen Reader | no |
VM | 0% |
Item | Value |
---|---|
Remote | Dev Container: Sandbox |
OS | Linux x64 5.10.76-linuxkit |
CPUs | Intel® Core™ i9-9980HK CPU @ 2.40GHz (8 x 2400) |
Memory (System) | 1.94GB (0.52GB free) |
VM | 0% |
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyl392:30425749
pythontb:30283811
pythonvspyt551:30345470
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
pythondataviewer:30285071
vscod805cf:30301675
pythonvspyt200:30340761
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
vsc1dst:30433059
pythonvs932:30410667
wslgetstarted:30433507
vsrem710:30416614
vsbas813:30436447
vscscmwlcmt:30433761
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Formatter black is not working on my VSCode...but why?
I use Black from inside VSCode and it rocks. It frees mental cycles that you would spend deciding how to format your code....
Read more >Editing Python in Visual Studio Code
Troubleshooting formatting ; Custom arguments for the formatter are incorrect. Check that the appropriate python.formatting.<formatter>Path setting does not ...
Read more >Is Your VS Code Extension Slow? Here's How to Speed it Up!
One possible cause is the number of files or the size of the extension. Some extensions have so much functionality in them that...
Read more >Using Alpine can make Python Docker builds 50× slower
Alpine Linux is often recommended as a smaller, faster Docker base image. But if you're using Python, it will slow down your build...
Read more >Visual Studio 2022 Release Notes | Microsoft Learn
Visual Studio 2022 version 17.4 is Available Today! ... You can now use Dev Containers for your C++ projects. You can learn more...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@adiun does it help if you set the formatter path and isort path?
@alkatar21 This is not an issue with the extension. The perf issues are due
conda run
itself being slow. That said if you want to tryout the prototype, we have you can find it here https://github.com/psf/black/issues/2883, https://github.com/hhatto/autopep8/issues/624