One `python3` call through a shim runs 14 to 16 shell scripts; macOS keeps ~1 KB of kernel memory for each nested one until reboot
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 53/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 领域
- cli, performance
调研方向
Start by tracing the shim call through the listed pyenv scripts: pyenv-hooks, pyenv-version-name, pyenv-version-file, pyenv-version-file-read, pyenv, pyenv-exec, pyenv-which, pyenv-prefix, and pyenv-latest. Compare the script launches for a global version and system, then look for ways to reduce launches while preserving version selection and execution behavior. Done when shim calls launch fewer scripts and the reported reproduction shows a corresponding reduction in kernel zone growth on macOS.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
The root bug is in macOS: when a script launches another #! script, the kernel keeps a 1 KB block in data.kalloc.1024 that only a reboot frees (independent write-up for macOS 26). pyenv hits it hard because one shim call is a chain of scripts. On a Mac running a lot of automated work, the zone reached 20 GB after 9.4 days and the machine panicked (zone map exhausted ... [data.kalloc.1024]). In a 10-minute process sample on that Mac, pyenv's scripts were the largest source of script launches; other scripts leak too.
Expected: pyenv can't fix the kernel, but fewer script launches per shim call would cut its share in proportion. Related: #2802.
Scripts launched per call (pyenv 2.8.15, fresh clone, no extra plugins)
I added echo "${0##*/}" >> log as line 2 of each executable script in a copy of the tree and ran python3 -c pass once through the shim.
- Global version set: the shim plus 15:
pyenv-hooksx4,pyenv-version-namex2,pyenv-version-filex2,pyenv-version-file-readx2,pyenv,pyenv-exec,pyenv-which,pyenv-prefix,pyenv-latest. system: the shim plus 13.
Kernel memory per call (macOS 15.7.3 24G419, Apple silicon)
2.8.15, global version set, 300 calls from a launchd job running a native binary (so no parent was a script), minus an idle window of the same length:
300 calls of python3 -I -c pass |
zone grew | idle window | net blocks per call |
|---|---|---|---|
| through the shim | 5,462 | 909 | 15.2 |
| interpreter run directly | 1,022 | 569 | 1.5 (noise) |
That is one clean run; two later runs were swamped by unrelated load and I discarded them. A traced copy of Homebrew pyenv 2.6.4 with system runs the same 13 scripts after the shim.
Reproduction steps
z() { zprint kalloc.1024 2>/dev/null | awk '$1 ~ /^data(_shared)?\.kalloc\.1024$/ {n+=$7} END {print n}'; }
z; for i in $(seq 300); do ~/.pyenv/shims/python3 -c pass; done; z
z; for i in $(seq 300); do "$(pyenv which python3)" -c pass; done; z
zprint worked without sudo on 15.7.3. Other processes also grow the zone, so use a quiet machine or compare with an idle window. Blocks are not returned afterwards.
Diagnostic details
- Platform: macOS 15.7.3 (24G419)
- Architecture: arm64
- pyenv: 2.8.15 (clone) and 2.6.4 (Homebrew)
- Python: 3.12.4
Measured and drafted with Claude Code.
- 主要语言
- Shell
- 星标
- 45.2k
- 派生
- 3.3k
- 平均合并
- 2 天 3 分钟
- 30 天内合并 PR
- 32
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pyenv/pyenv 的其他 Issue
-
discussion need-feedback type: documentation
难度 1/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
Refactor boilerplate code in PyPy scripts可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 4/5 3-5 天 新手友好度 45/100
维护者通常 1 天内回复
-
third-party third-party: python
难度 4/5 3-5 天 新手友好度 45/100
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
维护者通常 1 天内回复
-
by-design
难度 3/5 1-2 天 新手友好度 48/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
Abdk4Moura/tunlion#1014 ·
维护者通常 1 天内回复
-
icon request
难度 1/5 1 小时以内 新手友好度 85/100
PapirusDevelopmentTeam/papirus-icon-theme#4401 ·
维护者通常 3 天内回复
-
package-update
难度 1/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复