Skip to content

[perf] Replace only-path-without-wrappers with sed #1535

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

Merged
merged 3 commits into from
Oct 6, 2023

Conversation

mikeland73
Copy link
Contributor

Summary

This replaces our existing only-path-without-wrappers wrapper implementation to use sed.

Context:

We use only-path-without-wrappers to remove bin wrappers in the environment of our binaries. This is particularly useful when a binary calls another binary. See #1160 for more context. Unfortunately this adds a perf hit to every single binary call. In my informal experiments this cost was ~40ms. For example:

Previously, time go version was taking ~60ms even if environment is fully up to date.
Now, time go version takes ~20ms.

@Lagoja I'm getting an error in the elixer example (since that was the motivation for the original fix) but it looks like nix elixer on Sonoma is broken: https://elixirforum.com/t/bus-error-after-upgrading-to-sonoma-beta/56354/33 (Our CICD runners will test on Ubuntu and older macOS, Monterrey I believe)

How was it tested?

  • Tested time to call go version before and after
  • Inspected PATH of shell to ensure .wrappers was still there.
  • Copy pasted sed code from one of the bin wrappers

@mikeland73 mikeland73 requested review from savil and Lagoja October 6, 2023 04:33
Copy link
Collaborator

@savil savil left a comment

Choose a reason for hiding this comment

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

nice!

Args: cobra.ExactArgs(0),
PreRunE: ensureNixInstalled,
Use: "only-path-without-wrappers",
Deprecated: "This command is deprecated and will be removed after devbox 0.7.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets confirm this prints to Stderr and not Stdout, otherwise existing bin-wrappers may not work.

That said, I suppose we will re-generate the bin-wrappers due to the Devbox version change when this is released, so may be not a concern either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. It's actually OutOrStdErr which is currently Stderr, but we can't guarantee that. Will remove.

this bin-wrapper. Instead, we directly invoke the binary from the nix store, which
should be in PATH.

DO_NOT_TRACK=1 can be removed once we optimize segment to queue events.
This is implemented in sed for efficiency. sed is POSIX so we assume it's available.
Copy link
Collaborator

Choose a reason for hiding this comment

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

oh interesting. Availability was one of the concerns earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@savil if it's a concern we can implement in pure bash. Here's an implementation that only uses bash builtins:

IFS=: read -ra dirs <<< "$PATH"  # Split PATH into an array using colon as a delimiter

new_PATH=""
for dir in "${dirs[@]}"; do
    if [[ "$dir" != "/path/to/remove" ]]; then
        if [[ -z "$new_PATH" ]]; then
            new_PATH="$dir"
        else
            new_PATH="$new_PATH:$dir"
        fi
    fi
done

export PATH="$new_PATH"

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh not too bad. That's fairly understandable except for:

IFS=: read -ra dirs <<< "$PATH" 

:D

Copy link
Collaborator

Choose a reason for hiding this comment

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

but now that makes sense too...

@mikeland73 mikeland73 merged commit 0d0de12 into main Oct 6, 2023
@mikeland73 mikeland73 deleted the landau/remove-only-path-without-wrappers branch October 6, 2023 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants