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 AddProcessEnv #693

Merged
merged 1 commit into from
Apr 18, 2019
Merged

Conversation

umohnani8
Copy link
Contributor

AddProcessEnv was sequentially going through the env array
to check for duplicates, which would become very slow if we
add a huge amount of ENV vars.
Add a map to Generator to keep track of the ENV vars already
added, so that when AddProcessEnv checks for duplicates, it is
much faster.
Also add a new function called AddMultipleProcessEnv,
which takes a []string of ENVs and adds them to the config in one
go.
Add unit tests for these functions.

Signed-off-by: Urvashi Mohnani umohnani@redhat.com

@umohnani8
Copy link
Contributor Author

@mrunalp PTAL

@mrunalp
Copy link
Contributor

mrunalp commented Apr 10, 2019

LGTM

Approved with PullApprove

@mrunalp
Copy link
Contributor

mrunalp commented Apr 10, 2019

@vbatts ptal

@umohnani8
Copy link
Contributor Author

@vbatts ping :)

} else {
// else the env doesn't exist, so add it and add it's index to g.envMap
g.Config.Process.Env = append(g.Config.Process.Env, env)
g.envMap[key] = len(g.Config.Process.Env) - 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Why not
g.envMap[key] = env

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because, we want to keep track of the position in the string array this env is at so we can easily go in and update it if an existing env is added again with another value.

}
newEnvs := []string{"k1=v1", "k2=v2"}
expected := []string{"k1=v1", "k2=v2"}
g.AddMultipleProcessEnv(expected)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This should be newEnvs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

@vbatts
Copy link
Member

vbatts commented Apr 16, 2019

couple of thoughts, but otherwise LGTM

AddProcessEnv was sequentially going through the env array
to check for duplicates, which would become very slow if we
add a huge amount of ENV vars.
Add a map to Generator to keep track of the ENV vars already
added, so that when AddProcessEnv checks for duplicates, it is
much faster.
Also add a new function called AddMultipleProcessEnv,
which takes a []string of ENVs and adds them to the config in one
go.
Add unit tests for these functions.

Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
@umohnani8
Copy link
Contributor Author

@vbatts addresses comments, this should be ready now :)

@vbatts
Copy link
Member

vbatts commented Apr 17, 2019

LGTM

Approved with PullApprove

@umohnani8
Copy link
Contributor Author

Anything more we need to do to get this in?

@vbatts vbatts merged commit 095789d into opencontainers:master Apr 18, 2019
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.

4 participants