Repository navigation
性能优化:避免 Python 工具扫描依赖和缓存目录 - #3
Merged
Merged
Conversation
qingfengyuhuan
force-pushed
the
perf/python-workspace-scan
branch
from
November 11, 2026 02:38
1e8d0fc to
d1f0f00
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改动原因
code_execute在执行 Python 前后,会递归扫描整个工作区来检测文件变化。简单的 JSON 读取因此也会遍历虚拟环境、依赖和缓存目录,文件追踪成为主要耗时,并同步阻塞后端事件循环。本次改动
os.scandir()遍历,在进入目录前剪枝,避免遍历后再过滤。venv、.venv、node_modules、版本控制元数据、Python 缓存和框架构建缓存等目录。pyvenv.cfg识别自定义名称的 Python 虚拟环境,不跟随符号链接和目录联接。output、reports、build、dist等正常产物目录的文件变更检测。验证结果
同机回放耗时(Windows,每项各一次)
每次快照追踪的文件数从约 41,750 个降至 591 个。文件系统缓存和机器负载未固定,上述数字是本地单次回放样本,不代表总体分位数,也不是整轮大模型问答耗时的对比。
提交范围
本 PR 仅修改
backend/app/tool/builtin/code_execute.py。测试文件、性能测试产物、图表修改以及其他本地改动均未提交。