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

Improve performance of state tool #1467

Merged
merged 11 commits into from
Jul 23, 2021
Merged

Improve performance of state tool #1467

merged 11 commits into from
Jul 23, 2021

Conversation

Naatan
Copy link
Member

@Naatan Naatan commented Jul 22, 2021

Each commit addresses a different issue, so it might be easier to review this commit by commit.

@Naatan Naatan requested a review from mdrohmann July 22, 2021 23:40
mdrohmann
mdrohmann previously approved these changes Jul 23, 2021
Copy link
Collaborator

@mdrohmann mdrohmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -162,7 +162,7 @@ func run() (rerr error) {
mReload := mProjects.AddSubMenuItem("Reload", "Reload the local projects listing")
localProjectsUpdater := menu.NewLocalProjectsUpdater(mProjects)

localProjects, err := model.LocalProjects()
localProjects, err := model.LocalProjects(context.Background())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you use context.Background() everywhere. Is that correct? I assume that you have experimented with time-out contexts but determined that they are not necessary anymore.

I am fine if we leave this commit (814c6ed) as-is anyways as it gives us the flexibility to introduce timeouts here. But I would like to ensure that I understand it correctly that it does not change any behavior right now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just preserving the behavior that was there prior to this PR. I just made it more explicit.

Some of these could certainly benefit from a timeout, but they were not the focus of this PR.


baseUrl := fmt.Sprintf("http://127.0.0.1:%d", port)
return &Client{
Client: gqlclient.NewWithOpts(fmt.Sprintf("%s/query", baseUrl), 0, graphql.WithHTTPClient(http.DefaultClient)),
// The custom client bypasses http-retry, which we don't need for doing local requests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

svcManager := svcmanager.New(cfg)
require.NoError(t, svcManager.Start())

ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. It is used for testing. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we're not really using this particular context atm, the refactor was mainly so that I could use the context for NewSvcModel() appropriately. In the previous version we were reusing it for all client requests which will almost certainly eventually trigger a timeout in a way that it shouldn't.

var profilingEnabled = false

func init() {
profilingEnabled = os.Getenv(constants.ProfileEnvVarName) == "true"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We do not need an init() function for this initialization.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could swear Go didn't let you call functions outside of a function.. not sure why this works.

@Naatan Naatan merged commit be42910 into master Jul 23, 2021
@Naatan Naatan deleted the performance branch July 23, 2021 18:34
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

Successfully merging this pull request may close these issues.

2 participants