goimports performance degrades in go module

741 views
Skip to first unread message

Joseph Lorenzini

unread,
Nov 7, 2018, 7:43:33 PM11/7/18
to golang-nuts


Hi all,

If have a go.mod, goimports takes 30 seconds to run. If I remove the go.mod, then goimports takes half a second to run. Is this expected? Is goimports trying to do something with the packages found in go.mod? Is there a way to configure goimports so it ignores go.mod?

Thanks,
Joe

Sameer Ajmani

unread,
Nov 8, 2018, 9:01:37 AM11/8/18
to Joseph Lorenzini, Alan Donovan, Ian Cottrell, Michael Matloob, Rebecca Stambler, golang-nuts
+Tools team
30 seconds is much too slow for a tool that's used as a save hook. Ideally we're closer to 100ms; half a second is OK. Do we have a workaround for goimports+go.mod until the latency issues are resolved?
Thanks,
S


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ian Cottrell

unread,
Nov 8, 2018, 9:42:42 AM11/8/18
to jal...@gmail.com, golan...@googlegroups.com
Hi,

Could you try the module aware fork of goimports https://github.com/heschik/goimports and let us know if it works and is acceptable speed wise?
We are not merging it back yet because we think it may be slower for non module users, and we want some more confidence that it is a drop in replacement, but it should work.

Thanks
Ian

On Wed, Nov 7, 2018 at 7:43 PM Joseph Lorenzini <jal...@gmail.com> wrote:
--

Russ Cox

unread,
Nov 8, 2018, 3:37:06 PM11/8/18
to jal...@gmail.com, golan...@googlegroups.com, Ian Cottrell
On Wed, Nov 7, 2018 at 7:43 PM Joseph Lorenzini <jal...@gmail.com> wrote:
If have a go.mod, goimports takes 30 seconds to run. If I remove the go.mod, then goimports takes half a second to run. Is this expected? Is goimports trying to do something with the packages found in go.mod? Is there a way to configure goimports so it ignores go.mod?

That's not supposed to happen. It's hard to say what's going on with so little detail.
Can you give us a concrete go.mod and input.go file that causes 'goimports input.go' to take 30 seconds?

It looks like we dropped the ball and did not commit 
which we should probably do. But that was about better results, not speed.

Thanks.
Russ

Joseph Lorenzini

unread,
Nov 9, 2018, 10:26:50 AM11/9/18
to r...@golang.org, golan...@googlegroups.com, ianco...@google.com
Hi Ian/Russ,

I should have clarified that I was doing goimports -l on a directory of go packages. I know that's atypical. Its definitely not 30 seconds on a single file. It is however slower on a single file.

Here are the numbers for a single file using the official goimports tool:

goimports with go.mod: 101 milliseconds
goimports without a go.mod: 19 milliseconds

And Ian, here's the numbers for module aware go imports

goimports (module aware) with a go.mod: 306 milliseconds
goimports(module aware) without a go.mod: 73 milliseconds

Russ in regards to reproducing the problem, here's my go.mod file: https://gist.github.com/jaloren/6a5908507794e2fec28c403af506855f. As for the input file, it doesn't matter what the go file is as long as the imports in the file are out of order. The slow down happens when goimports need to rearrange the imports so standard packages are on top and third party packages are on the bottom.

Hope that helps.

Joe




roger peppe

unread,
Nov 10, 2018, 3:46:42 AM11/10/18
to Joseph Lorenzini, rsc, golang-nuts, ianco...@google.com
I will add that I regularly see goimports with modules take many seconds to run. I'm using acmego and I sometimes end up needing to switch that off because it corrupts text seconds after a save.

wilk

unread,
Nov 10, 2018, 8:14:33 AM11/10/18
to golan...@googlegroups.com
On 08-11-2018, 'Ian Cottrell' via golang-nuts wrote:
> --000000000000ea8501057a283d99
> Content-Type: text/plain; charset="UTF-8"
>
> Hi,
>
> Could you try the module aware fork of goimports
> https://github.com/heschik/goimports and let us know if it works and
> is
> acceptable speed wise?
> We are not merging it back yet because we think it may be slower for
> non
> module users, and we want some more confidence that it is a drop in
> replacement, but it should work.

I felt again in the trap of using a module name without dot (for quick
tests)! Even if I know that it's highly recommended to use a module
name with a dot (there are others issues with this)
It doesn't works with your fork, it works with golang.org/x/tools/

Can we say now officially that a dot in a module name is mandatory ?

>
> Thanks
> Ian
>
> On Wed, Nov 7, 2018 at 7:43 PM Joseph Lorenzini <jal...@gmail.com> wrote:
>
>>
>>
>> Hi all,
>>
>> If have a go.mod, goimports takes 30 seconds to run. If I remove the
>> go.mod, then goimports takes half a second to run. Is this expected? Is
>> goimports trying to do something with the packages found in go.mod? Is
>> there a way to configure goimports so it ignores go.mod?
>>
>> Thanks,
>> Joe
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>


--
William

Todd Neal

unread,
Nov 10, 2018, 3:27:33 PM11/10/18
to golang-nuts
I tracked this down (at least it was the source of a slow goimports for me) and put up a CL at https://go-review.googlesource.com/c/tools/+/132598/ .The issue was that it's eventually exec'ing the go command for every import in the presence of modules, which adds up quickly and also doesn't easily show up in profiling.

- Todd
Reply all
Reply to author
Forward
0 new messages