microsoft / vscode-isort

Import sorting for python using the isort library.
https://marketplace.visualstudio.com/items?itemName=ms-python.isort
MIT License
87 stars 21 forks source link

Enabling the extension makes save very slow #160

Open alonme opened 1 year ago

alonme commented 1 year ago

vscode Version: 1.73.1 python extension version: v2022.18.2 isort extension version: v2022.6.0

The extension makes saving files very slow (around 5 seconds).

This was not the experience when i was using the isort in the past with this config.

"[python]": {
        "editor.codeActionsOnSave": {
            "source.organizeImports": true,
        }
    }

also - i can't seem to find a way to use isort as i was doing before?

karthiknadig commented 1 year ago

You can use it via Organize Import command. You can turn off "source.organizeImports" by removing this from your settings.

sbdchd commented 1 year ago

Also running into this, running the underlying commands on the command line:

cat foo.py | ./backend/.venv/bin/python -m isort - --filename foo.py

takes about 660ms (not great)

while saving a file in vscode with isort enabled takes ~4000ms

edit: I don't remember the vscode-python extension (https://github.com/microsoft/vscode-python/issues/7042) having the same issue

alonme commented 1 year ago

@karthiknadig - i don't want to remove it - as i want it to run on save, however since updating to the new version (and disabling the isort extension) - my previous configuration does not work..

i am looking for a way to understand why it doesn't run / make it run again

karthiknadig commented 1 year ago

@sbdchd @alonme Can you share the logs from output > isort after setting isort.loglevel to debug?

my previous configuration does not work

We are migrating to this extension so the isort feature in python extension is now handled via this extension. So, it does not work if you disable this. You could revert to python extension from september 2022 and that should still support the old way. Meanwhile we will continue to work with isort (upstream) to diagnose and resolve these issues.

sbdchd commented 1 year ago

I've since switched to Ruff to handle import sorting so I'm not longer able to reproduce

tylerlaprade commented 1 year ago

It is also extremely slow for me.

hoto17296 commented 10 months ago

I also faced a similar problem. I'm not sure why, but I solved it by reinstalling the extension.

tylerlaprade commented 10 months ago

We're already using Ruff, which has identical functionality, so I consolidated to only use Ruff. I uninstalled the isort extension. It's unbelievably fast!

karthiknadig commented 10 months ago

We recommend using ruff as well. It uses the same server underneath as this extension, but ruff itself is incredibly fast. Since it also handles formatting like black it can do import sorting and code formatting in one step.