-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Resolve shell env API performance issue for single env approach #238488
base: main
Are you sure you want to change the base?
Conversation
https://github.com/user-attachments/assets/57167cc9-fd5b-424b-b302-83542592365d |
|
||
for i in "${!vsc_env_keys[@]}"; do | ||
if [[ "${vsc_env_keys[$i]}" == "$key" ]]; then | ||
if [[ "${vsc_env_values[$i]}" != "$value" ]]; then |
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.
this allow us to only printf and send to VS Code if there is a difference in terms of value.
builtin printf '\e]633;EnvSingleEntry;%s;%s;%s\a' "$key" "$(__vsc_escape_value "$value")" "$__vsc_nonce"
below allow us to send to VS Code if it is a brand new variable.
builtin printf '\e]633;EnvSingleEntry;%s;%s;%s\a' "$key" "$(__vsc_escape_value "$value")" "$__vsc_nonce" | ||
} | ||
|
||
trackMissingEnvVars() { |
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 now track a cached Map (two array because associate array are only supported in bash version 4.0 or above), we also need to make sure environment variable deletion gets accounted. Both in bash side and VS Code side.
If there is an environment variable that was cached before but not in user's environment variable list anymore, we need to detect that and update the map accordingly, and let VS Code know. (by something like EnvSingleDelete.. etc
# builtin printf "Time taken: $elapsed_time seconds\n" | ||
|
||
trackMissingEnvVars | ||
builtin printf "Time taken: $elapsed_time seconds\n" |
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.
Although we have more loops now in the script, time is actually shorter because we use the least number of printf statement as much as possible, avoid using printenv, and compgen.
Check this by looking at the time calculation and just how things feel.
Potential root of the performance cause:
Edit: d3ef701 brought back instant bash prompts. I think it was combination of printenv with compgen and tons of printf statements really slowing things down. So Mainly
Scenario number 3 was correct