High CPU usage in idle TUI mode (unbounded render / busy-loop in main thread)
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 66/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- rust
- 领域
- cli, performance
调研方向
The report identifies the main thread inside the tokio runtime and names terminal.draw() and event polling as the suspected loop, but it gives no source file or test path. Start by locating the TUI event loop and checking whether it waits for input between redraws. Done means the idle TUI no longer keeps a CPU core busy while input and redraw behavior still work.
由索引模型根据 Issue 内容生成。
描述
Environment
- OS: Arch Linux (7.2.14-arch1-1)
- code2prompt version: 4.3.0
- Terminal: alacritty 0.17.0 (94e7c887)
Description
When running code2prompt in interactive TUI mode and leaving it idle (without touching any keys), the process constantly pegs a CPU core at 100%.
Root Cause / Investigation
Profiling the running process with gdb and perf top revealed that:
- All Rayon workers (threads 2–13) and Tokio workers (threads 14–25) are completely idle and sleeping in futex/condvars.
- The entire CPU load is on Thread 1 (main thread).
- The main thread is caught in a tight render busy-loop without waiting/blocking for input events. On every loop iteration, it redraws the UI and clones/drops the file tree.
perf top breakdown:
- ~5%
<alloc::vec::Vec<T,A> as core::clone::Clone>::clone - ~4%
ratatui_core::buffer::buffer::Buffer::index_of - ~3.4%
ratatui_core::buffer::buffer::Buffer::set_style - ~3.1%
<ratatui_core::buffer::diff::BufferDiff as Iterator>::next - ~2.7%
<ratatui_core::buffer::cell::Cell as PartialEq>::eq - ~2.7%
<alloc::string::String as Clone>::clone - Churn in
malloc/cfreeanddrop_in_place<[code2prompt::model::DisplayFileNode]>
It looks like the event loop lacks blocking event polling (e.g. crossterm::event::poll with a reasonable tick rate / timeout or blocking read), causing terminal.draw() to spin continuously in the background.
GDB Backtrace (Thread 1)
Thread 1 (Thread 0x7f63a0354680 (LWP 124312) "code2prompt"):
#0 0x000055c89c83a4a1 in <alloc::string::String as core::clone::Clone>::clone ()
#1 0x000055c89bf94fff in <alloc::vec::Vec<T,A> as core::clone::Clone>::clone ()
#2 0x000055c89bf9502e in <alloc::vec::Vec<T,A> as core::clone::Clone>::clone ()
#3 0x000055c89bf9502e in <alloc::vec::Vec<T,A> as core::clone::Clone>::clone ()
#4 0x000055c89bffb661 in code2prompt::main::{{closure}} ()
#5 0x000055c89c0002b9 in tokio::runtime::park::CachedParkThread::block_on ()
#6 0x000055c89bff6fb0 in tokio::runtime::context::runtime::enter_runtime ()
#7 0x000055c89c000462 in tokio::runtime::runtime::Runtime::block_on ()
#8 0x000055c89bfee232 in code2prompt::main ()
- 主要语言
- Rust
- 星标
- 7.8k
- 派生
- 459
- 平均合并
- 3 天 20 小时
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
mufeedvh/code2prompt 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
mufeedvh/code2prompt#355 ·
-
Symlink-to-file inside scanned root reads file content outside the root without --follow-symlinks未关闭
难度 2/5 1-3 小时 新手友好度 72/100
mufeedvh/code2prompt#354 ·
-
No tag 4.3.0未关闭
难度 1/5 1 小时以内 新手友好度 72/100
mufeedvh/code2prompt#340 · 1 个 reaction ·
-
难度 3/5 1-2 天 新手友好度 62/100
mufeedvh/code2prompt#356 ·
-
难度 3/5 1-2 天 新手友好度 52/100
mufeedvh/code2prompt#345 ·
查看 mufeedvh/code2prompt 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
topgrade-rs/topgrade#2540 ·
维护者通常 1 天内回复
-
Invalid JSON options for ngram and edge_ngram silently use defaults可能已有人在做 @Tilendlesa 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
noemaforge/vimanam#153 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 3 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复