Skip to content

~30% CPU usage while waiting for model response — possibly spinner-driven render loop at 60 FPS #22017

@rubdos

Description

@rubdos

Description

While OpenCode is waiting for a model response (spinner visible, no streaming yet), I'm seeing ~30% CPU on Linux. I did some digging and have a hypothesis about the cause.

Claude Sonnet tells me this:

  1. targetFps: 60 in rendererConfig() (packages/opencode/src/cli/cmd/tui/app.tsx)
    The renderer appears to be configured at 60 FPS — double opentui's default of 30. This sets minTargetFrameTime = ~16ms.
  2. opentui-spinner may be driving the render loop via raw setInterval
    The spinner component uses an 80ms interval (12.5 FPS). From what I can tell, opentui-spinner calls requestRender() on every tick via a raw setInterval rather than the Timeline system, scheduling a full frame every 80ms.
  3. Per-frame JS cost may not be gated on dirty state

opentui's JS-side render loop appears to walk the entire renderable tree and run Yoga layout on every frame. The native lib.render() already does cell diffing so the terminal write cost is cheap (just the spinner chars), but I couldn't find any path where renderSelf() is skipped for non-dirty renderables — the _dirty flag seems to be used for Yoga layout only.

The result seems to be ~12.5 full render frames/sec continuously while just waiting, with each frame doing a full Yoga + JS tree traversal regardless of what actually changed.

Environment

  • OS: Arch Linux
  • opencode: v1.4.1 from repos

Plugins

"@tarquinen/opencode-dcp@latest", "opencode-agent-memory@0.2.0", "oh-my-opencode-slim@0.9.5", "@slkiser/opencode-quota"

OpenCode version

1.4.1

Steps to reproduce

  1. Have a long-running request on a laptop
  2. Feel your lap heating up a bit

(I don't think there's anything particular to this, but I'll be happy to dig deeper)

Screenshot and/or share link

No response

Operating System

Arch Linux

Terminal

Alacritty

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingopentuiThis relates to changes in v1.0, now that opencode uses opentuiperfIndicates a performance issue or need for optimization

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions