-
Notifications
You must be signed in to change notification settings - Fork 144
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
Conversation
@mrunalp PTAL |
@vbatts ptal |
@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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
generate/generate_test.go
Outdated
} | ||
newEnvs := []string{"k1=v1", "k2=v2"} | ||
expected := []string{"k1=v1", "k2=v2"} | ||
g.AddMultipleProcessEnv(expected) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
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>
@vbatts addresses comments, this should be ready now :) |
Anything more we need to do to get this in? |
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