Cache context budget instead of recomputing every frame

budget() called tiktoken on every UI tick, which was the main CPU hog
during rapid key input. Move the cached ContextBudget onto ContextState
and recompute only when entries actually change (push_entry, compact,
restore_from_log).

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-06 18:36:33 -04:00
parent 49cd6d6ab6
commit f4664ca06f
3 changed files with 17 additions and 12 deletions

View file

@ -828,7 +828,7 @@ impl ScreenView for InteractScreen {
agent.expire_activities();
app.status.prompt_tokens = agent.last_prompt_tokens();
app.status.model = agent.model().to_string();
app.status.context_budget = agent.budget().status_string();
app.status.context_budget = agent.context.budget.status_string();
app.activity = agent.activities.last()
.map(|a| a.label.clone())
.unwrap_or_default();