High CPU usage in idle TUI mode (unbounded render / busy-loop in main thread)
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 66/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- rust
- Bereich
- cli, performance
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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 ()
- Vorherrschende Sprache
- Rust
- Sterne
- 7.8k
- Forks
- 459
- Ø Merge
- 3 T. 20 Std.
- Gemergte PRs (30 T.)
- 1
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus mufeedvh/code2prompt
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
mufeedvh/code2prompt#355 ·
-
Symlink-to-file inside scanned root reads file content outside the root without --follow-symlinksOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
mufeedvh/code2prompt#354 ·
-
No tag 4.3.0Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
mufeedvh/code2prompt#340 · 1 Reaktion ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 62/100
mufeedvh/code2prompt#356 ·
-
Vim navigation featureOffen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 52/100
mufeedvh/code2prompt#345 ·
Alle Issues in mufeedvh/code2prompt
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
pop-os/cosmic-applets#1641 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
pop-os/cosmic-store#650 ·
-
CI/CD ignore-for-release
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
eclipse-ankaios/ankaios#844 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
hyperlight-dev/hyperlight-js#459 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag