jetify-com / devbox

Instant, easy, and predictable development environments
https://www.jetify.com/devbox/
Apache License 2.0
8.62k stars 198 forks source link

Devbox global shellenv slows down shell startup #1886

Open dudicoco opened 7 months ago

dudicoco commented 7 months ago

What happened?

Adding eval "$(devbox global shellenv)" to my .zshrc causes adds almost half a second to my shell startup time. Is this command making network calls? I am not sure why or how this command takes so long to complete.

Steps to reproduce

1.

~ > time  zsh -i -c exit
zsh -i -c exit  0.02s user 0.02s system 46% cpu 0.098 total
  1. Add eval "$(devbox global shellenv)" to .zshrc
  2. ~ > time  zsh -i -c exit
    zsh -i -c exit  0.10s user 0.10s system 37% cpu 0.545 total

Command

global

devbox.json

No response

Devbox version

0.9.1

Nix version

nix (Nix)2.16.1

What system does this bug occur on?

macOS (Apple Silicon)

Debug logs

No response

slavaGanzin commented 2 weeks ago

Shell script adds 250ms

time devbox 

________________________________________________________
Executed in  565.80 millis    fish           external
   usr time  165.44 millis    0.39 millis  165.05 millis
   sys time  101.30 millis    6.92 millis   94.38 millis

Shell script launches binary:

cat (which devbox) | grep INSTALL_DIR

readonly INSTALL_DIR="${HOME}/.cache/${TOOL_NAME}/bin"
    local -r installed_version=$(ls "${INSTALL_DIR}/" 2>/dev/null | sort -rV | head -n 1 | grep -oE 'v?[0-9]+\.[0-9]+\.[0-9]+-?[a-zA-Z]*')
    local -r bin_dir="${INSTALL_DIR}/${version}_${platform}"
    local -r bin="${INSTALL_DIR}/${version}_${platform}/${TOOL_NAME}"
        echo "INSTALL_DIR: ${INSTALL_DIR}"

And binary is not that fast as well:

time ~/.cache/devbox/bin/0.13.4_darwin_amd64/devbox

________________________________________________________
Executed in  214.63 millis    fish           external
   usr time  152.89 millis    0.23 millis  152.66 millis
   sys time   51.53 millis    2.91 millis   48.62 millis

For comparison:

time ls --help

________________________________________________________
Executed in   15.87 millis    fish           external
   usr time    4.26 millis    0.20 millis    4.06 millis
   sys time    7.46 millis    3.81 millis    3.66 millis

Shame for asking to add this to your init sh!

It works so slow, that I thought devbox is written in python :)