High CPU usage in idle TUI mode (unbounded render / busy-loop in main thread)

Ouverte
#352 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
66/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
rust
Domaine
cli, performance

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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:

  1. All Rayon workers (threads 2–13) and Tokio workers (threads 14–25) are completely idle and sleeping in futex/condvars.
  2. The entire CPU load is on Thread 1 (main thread).
  3. 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/cfree and drop_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 ()
bd9ccae75ce72a4ddb4260b3c0743e13

code2prompt_backtrace.txt

Langage dominant
Rust
Étoiles
7.8k
Forks
459
Merge moyen
3 j 20 h
PR mergées (30 j)
1

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de mufeedvh/code2prompt

Toutes les issues de mufeedvh/code2prompt

Issues similaires

Plus d'issues Rust

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.