-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/tools/gopls: slow imports / formatting #36034
Comments
Note that we need |
Thanks for following up. Essentially, my workflow is the tried and true "hit save and run goimports", i.e. I want formatting, import sorting, and adding of missing imports on whatever code I save. What I'm observing is that import sorting and adding of missing imports isn't much faster than goimports. And, when combined with code that needs to be formatted, I'm seeing the formatting happen much much later (a few seconds after imports are fixed), or not at all (and another save then triggers it). Here is a gist with two logs where I tried to perform similar actions, one with https://gist.github.com/zikaeroh/fc08a33efd1f14aab420789a978d4205 Additionally, here are two screencasts showing the kind of slowness I'm referring to. These are not the same as what's in the logs, but I can try and produce matching logs/screencasts if needed. With goimports: https://streamable.com/pwmgs With gopls: https://streamable.com/id6ce I wasn't able to capture the "imports get sorted, then a few seconds later the formatting happens" in the gopls screencast (for some reason), but I'll try to capture it if I see it pop up. My go-related config:
|
Since the screencaps don't show keystrokes, the only way to show the save events is to look at the tab indicator icon VS Code shows for unsaved files. Hopefully the logs will show didSave events to help line things up within those logs, but if it's critical I can attempt to take a screencap with some keypresses. |
Sorry for the delay on this, last week was hectic. Needless to say, I still can't reproduce the problem... Not sure what to make of this yet. I don't think it has all that much to do with imports per se. Request 48, for example, takes 694ms. But almost all of that time is actually just spent waiting for a previous request to finish a
Request 19 is also slow, in the actual goimports code this time, but that's the first scan before anything is cached, so I don't think there's much to be learned there. Sorry, I think I'm going to need more logs to nail this down. If you can give a snippet from a natural occurrence, rather than a forced repro, that would be ideal. But I understand that might not be convenient, so whatever you can do. |
One note, actually -- changing the imports block like this is a worst case for gopls because it triggers |
I guess I don't know what distinguishes a "natural occurrence", then... It's pretty common when I'm writing code that I both have a missing import (new code, new imports) and formatting to clean up (extra newlines, spacing). I find myself having to wait / save again after imports get sorted to get things to the right state. I can just bulk record logs as I work on something, and hope to find something, but know that I definitely won't be able to do any sort of screencasting.
What do you mean by this? Specifically just changing anything but imports? Because I can't really say I experience slowness if imports aren't changing. A plain format is fast. It's the two together (i.e. goimports-style formatting) where I see slowness. Presumably, it's going to be fast if gopls never has to deal with any new packages. |
That's totally fine -- the log is sufficient. I don't really need the screencasts at all for this, I should be able to piece things together from the logs if I absolutely have to.
Yeah, I guess what I meant was that if you're doing the kind of stuff in the screencast, changing imports very fast, then I'm not surprised if gopls starts tripping over itself. A less synthetic example would help make sure I'm focused on the right problem.
Maybe this is the actual problem. Would you be so worried about the performance if you didn't have to do things twice? I would be interested to see a log of formatting not happening, maybe as a separate bug. FWIW, with completeUnimported all this should matter less, because the import statement will show up in the right place before you save. |
The "very fast" is really only because I'm trying to keep the screencast short. I can delete something, wait a bit, then save and it'd be slow.
Maybe not, but in the past I had been getting format + import all in one go. Since the race condition was fixed, I haven't seen it happen in one step anymore. Maybe fixing the bug means that my editor's no longer applying two changes, or something, and it's picking organize first and just not bothering to try and finish the rest.
I assume by this you mean accepting a completion item which includes a TextEdit that adds the import. There are cases where I don't get those at all (completely missing the thing I want even though it's somewhere in my deps), or they are a bunch of things I'm not interested in (even though I've used many of them in my project already), where it's better for me to simply not accept the completion, write it out by hand, then save. I believe there's an open issue about sorting those better (i.e. sorting direct module dependencies first), which would help somewhat. A concrete example is when I try to write a new test file, then type |
Right. There were always technically two calls, but imports would do formatting so yeah.
#36077. Mailed https://golang.org/cl/212021.
For sure. That's https://golang.org/cl/211538, but will require 1.14. |
The thing that bugs me about But that's not relevant to the formatting + organize being slow. 🙂 |
@heschik
I'm not sure this is synthetic; if a user is adding/adjusting an import, with deltas being sent to Consider the following:
with the cursor where the This isn't hypothetical because this is exactly how I (sometimes) add imports in Vim; I have a plugin that automatically adds the closing |
Currently too slow: golang/go#36034
@zikaeroh I believe we discussed on Slack that this had gotten much better. Close? |
For me, I feel like it's pretty good at the moment (I've kept gopls's format+organize on since the race was fixed to test and haven't been too irritated), but Paul's comments above might need addressing. I can provide feedback again if I find that it's slow for the "format and organize and add imports" situation. |
Meh, I'm gonna close this and we can reopen/refile if it actually shows up. |
@zikaeroh reported slow import organization and formatting in #35388. Filing this issue to follow up. If anyone else experiences similar issues, please comment below and attach
gopls
logs if possible.The text was updated successfully, but these errors were encountered: