Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

`~/.vite-plus/env` costs 85-315 ms per shell start on long PATHs (super-linear `${var#*pattern}` in the dedupe loop)

Đã đóng Phù hợp với người mới
#2,898 0 bình luận 3 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Một pull request liên quan đã được merge.

  • #2905 của @jonatankruszewski — đã merge

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
bash, rust, shell, zsh

Hướng nghiên cứu

Mẫu môi trường POSIX là ENV_TEMPLATE_POSIX trong crates/vp_global_cli/src/commands/env/setup.rs. Thay thế vòng lặp loại bỏ trùng lặp ${__vp_tmp#*":${__vp_dir}:"} bằng bản xây dựng lại phân tách IFS được đưa ra trong issue để PATH vẫn tuyến tính trên zsh, bash và dash. Chèn bản viết lại vào snapshot runner hiện có từ #2494 (sh, bash, zsh) và xác nhận rằng ~/.vite-plus/env được phát ra vẫn tạo ra cùng một PATH.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

contribution welcome

Summary

The PATH dedupe loop in the POSIX env script (ENV_TEMPLATE_POSIX in crates/vp_global_cli/src/commands/env/setup.rs, introduced by #2494, shipped as ~/.vite-plus/env) runs

__vp_after="${__vp_tmp#*":${__vp_dir}:"}"

once per occurrence of each vp dir in PATH. ${var#*X} (shortest-prefix removal with a leading *) is super-linear in the offset of X on every POSIX shell I tested. With a PATH of ~8 KB (147 entries, which is what mise activate produces for a user with ~110 globally installed tools) each expansion takes 50-260 ms depending on the shell, and the loop runs twice (bin and fallback-bin).

Because the installer puts . "$HOME/.vite-plus/env" into ~/.zshenv, this is paid by every zsh process on the machine, interactive or not: zsh -c true goes from 0 ms to 180 ms. Every #!/usr/bin/env zsh script, every zsh -c from a tool, every IDE env probe pays it.

Environment: vp v1.0.0, macOS 26 arm64, zsh 5.9 (/bin/zsh) and 5.9.2 (brew), bash 5.3.15 and 3.2, dash.

Repro (zsh, 3 lines)

PATH="$(printf '/Users/me/.local/share/mise/installs/tool-%03d/latest/bin:' {1..140})/x/bin"; tmp=":${PATH}:"; d=/x/bin
typeset -F3 SECONDS=0; a="${tmp#*":${d}:"}";  print "#*  : ${SECONDS}s"
SECONDS=0;              b="${tmp%%":${d}:"*}"; print "%%* : ${SECONDS}s"
#*  : 0.109s
%%* : 0.000s

Measurements

Single ${tmp#*":${dir}:"} on an 8.7 KB PATH, target dir last:

shell #* (shipped) %%
zsh 5.9 147 ms 5 ms
zsh 5.9.2 146 ms 5 ms
bash 5.3.15 63 ms 14 ms
bash 3.2 53 ms 13 ms
dash 264 ms 4 ms

Cost of sourcing the whole env file in zsh -f as PATH grows (vp dirs present, so the loop runs):

PATH entries chars time
20 1353 4 ms
40 2653 13 ms
80 5253 51 ms
147 9656 172 ms
300 19754 720 ms

Whole env file from the real 147-entry PATH, median of 5:

file zsh 5.9 zsh 5.9.2 bash 5.3 bash 3.2 dash
shipped ~/.vite-plus/env 177 178 85 83 315
literal-prefix one-liner (see below) 6 6 128 133 147
IFS-split loop (proposed) 6 6 9 13 5

Proposed fix

A literal-prefix strip (__vp_after="${__vp_tmp#"${__vp_before}:${__vp_dir}:"}") fixes zsh but makes bash and dash slower (table above). Splitting PATH on : once and rebuilding it is linear on every shell and produced an identical PATH to the current script in /bin/sh, dash, bash 3.2, bash 5.3 and zsh for a PATH containing both vp dirs, one of them twice:

__vp_bin="$HOME/.vite-plus/bin"
__vp_fallback="$HOME/.vite-plus/fallback-bin"
__vp_new=
__vp_ifs=$IFS
IFS=:
if [ -n "${ZSH_VERSION-}" ]; then setopt localoptions shwordsplit noglob; else set -f; fi
for __vp_p in $PATH; do
  case "$__vp_p" in "$__vp_bin"|"$__vp_fallback") ;; *) __vp_new="${__vp_new:+${__vp_new}:}${__vp_p}" ;; esac
done
IFS=$__vp_ifs
[ -n "${ZSH_VERSION-}" ] || set +f
PATH="${__vp_bin}${__vp_new:+:${__vp_new}}:${__vp_fallback}"
export PATH
unset __vp_bin __vp_fallback __vp_new __vp_ifs __vp_p

The snapshot runner from #2494 already exercises the file in sh, bash and zsh, so the rewrite can slot into the same tests.

Who hits this

Anyone whose PATH is long when a nested shell starts: mise/asdf/nix users with many tools, monorepo devs with per-package bin dirs, CI images. A fresh login shell with a 30-entry PATH pays ~4 ms, which is why it is easy to miss.

Ngôn ngữ chính
Rust
Star
6k
Fork
271
Merge trung bình
1 ngày 14 giờ
Pull request đã merge (30 ngày)
183

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của voidzero-dev/vite-plus

Tất cả issue của voidzero-dev/vite-plus

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.