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


On Saturday, November 10, 2018 at 2:46:42 AM UTC-6, rog wrote:
>
> 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.
>
> On Fri, 9 Nov 2018, 3:26 pm Joseph Lorenzini <jal...@gmail.com 
> <javascript:> wrote:
>
>> 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
>>
>>
>>
>>
>>
>> On Thu, Nov 8, 2018 at 2:36 PM Russ Cox <r...@golang.org <javascript:>> 
>> wrote:
>>
>>> On Wed, Nov 7, 2018 at 7:43 PM Joseph Lorenzini <jal...@gmail.com 
>>> <javascript:>> 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 
>>> https://go-review.googlesource.com/c/tools/+/128362/2/imports/fix.go,
>>> which we should probably do. But that was about better results, not 
>>> speed.
>>>
>>> Thanks.
>>> Russ
>>>
>>> -- 
>> 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 <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to