优化:将运行时上下文探测从同步改为异步+缓存+预热#118
Closed
xinggitxing wants to merge 1 commit into
Closed
Conversation
…and prewarm The synchronous getRuntimeContext() spawned 5 Git Bash child_process calls sequentially on Windows, blocking the event loop ~12s on startup. Convert all probes (uname, python3 --version, node --version, rg, jq) to async, running them in parallel via Promise.all. Cache the result so subsequent calls are instant. Add prewarmRuntimeContext() called from the SessionManager constructor so computation starts while the user is typing. Also adds an error .catch() to prewarmRuntimeContext to log background failures instead of silently swallowing rejected promises.
Collaborator
|
@xinggitxing 问题2:这个PR的逻辑跟main分支有差异,具体是PR会缓存 问题3:目前env环境参数虽然是串行获取,也只耗时0.15秒(windows系统实测),并没有耗时12秒这么多。
|
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.

背景
getRuntimeContext()原为同步函数,在 Windows 上依次 spawn 5 次 Git Bash(
uname -a、python3 --version、node --version、command -v rg、command -v jq),累计阻塞事件循环约 12 秒,严重影响启动体验。改动内容
src/prompt.ts— 核心重构getUnameInfoAsync()、getCommandVersionAsync()、checkToolInstalledAsync()、getRuntimeVersionInfoAsync()Promise.all并发执行所有探测,消除串行阻塞runtimeEnvJsonPromise(防并发重复触发)+runtimeEnvJsonCached(后续调用直接返回缓存的 JSON)
prewarmRuntimeContext():在SessionManager构造时后台预计算,用户输入时结果可能已就绪
.catch()错误日志,避免静默吞异常src/session.ts— 集成调用prewarmRuntimeContext(this.projectRoot)启动后台预热getRuntimeContext()调用改为awaitsrc/tests/prompt.test.ts— 测试适配async并await getRuntimeContext()效果
os.type()等内置 API)