Skip to content
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

Extremely slow golines formatting for specific function #106

Open
Meelfy opened this issue Jun 6, 2023 · 1 comment
Open

Extremely slow golines formatting for specific function #106

Meelfy opened this issue Jun 6, 2023 · 1 comment

Comments

@Meelfy
Copy link

Meelfy commented Jun 6, 2023

I've encountered a very peculiar issue with the golines tool when formatting the following function:

func TestInitTestConfig(t *testing.T) {
    assert.Equal(t, LocalConfig.Abase.Cluster, "")
    InitTestConfig()
    assert.Equal(t, LocalConfig.Abase.Cluster, "abase_aurora")
}

Running golines on this file takes an astonishing 6.82 seconds:

%  time golines -d -m 120 -w ./src/settings/local_test.go
[2023-06-06 10:03:25] DEBUG Processing file ./src/settings/local_test.go
[2023-06-06 10:03:28] DEBUG Starting round 0
[2023-06-06 10:03:28] DEBUG Nothing more to shorten or reformat, stopping
[2023-06-06 10:03:31] DEBUG Contents unchanged, skipping write
golines -d -m 120 -w ./src/settings/local_test.go  6.82s user 30.91s system 638% cpu 5.905 total

The complete file is as follows:

package settings

import (
    "testing"

    "github.com/stretchr/testify/assert"
)

func TestInitTestConfig(t *testing.T) {
    assert.Equal(t, LocalConfig.Abase.Cluster, "")
    InitTestConfig()
    assert.Equal(t, LocalConfig.Abase.Cluster, "abase_aurora")
}

func TestInitLocalConfig(t *testing.T) {
    err := InitLocalConfig()
    assert.NoError(t, err)
}

However, when I remove the TestInitTestConfig function, golines only takes 0.01 seconds:

%  time golines -d -m 120 -w ./src/settings/local_test.go
[2023-06-06 10:04:09] DEBUG Processing file ./src/settings/local_test.go
[2023-06-06 10:04:09] DEBUG Starting round 0
[2023-06-06 10:04:09] DEBUG Nothing more to shorten or reformat, stopping
[2023-06-06 10:04:09] DEBUG Contents unchanged, skipping write
golines -d -m 120 -w ./src/settings/local_test.go  0.01s user 0.01s system 86% cpu 0.020 total

The complete file is as follows:

package settings

import (
    "testing"

    "github.com/stretchr/testify/assert"
)

func TestInitLocalConfig(t *testing.T) {
    err := InitLocalConfig()
    assert.NoError(t, err)
}

This significant difference in performance is quite baffling, and I'm not sure what could be causing it. Any insights or suggestions would be greatly appreciated.

@telemachus
Copy link
Contributor

I can't reproduce this here. What versions of go and golines are you using?

# First run
$ time golines -d -m 120 -w .
[2023-06-08 20:16:31] DEBUG Processing file main.go
[2023-06-08 20:16:31] DEBUG Starting round 0
[2023-06-08 20:16:31] DEBUG Nothing more to shorten or reformat, stopping
[2023-06-08 20:16:32] DEBUG Contents changed, writing output to main.go

real	0m0.607s
user	0m1.361s
sys	0m2.490s

# Second run
$ time golines -d -m 120 -w .
[2023-06-08 20:16:47] DEBUG Processing file main.go
[2023-06-08 20:16:48] DEBUG Starting round 0
[2023-06-08 20:16:48] DEBUG Nothing more to shorten or reformat, stopping
[2023-06-08 20:16:48] DEBUG Contents unchanged, skipping write

real	0m0.605s
user	0m1.356s
sys	0m2.452s
  • golines v0.11.0
  • go version go1.20.5 darwin/amd64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants