Skip to content

UI widgets: mark-dirty-on-change, repaint at most every 100ms #1093

@xusheng6

Description

@xusheng6

Follow-up to the worker-queue / state-on-worker discussion (#1090, #1088, #1089).

Problem

Every debugger event currently drives an immediate UI update on the dispatcher thread. Each widget that subscribes (register view, stack view, thread frames, modules, locals, IP highlight, statusbar, …) reacts inline. That's fine at normal user pace, but it caps the maximum stepping rate at "how fast can Qt repaint all the widgets," which is far slower than the engine can step.

Concretely: holding F11 to step rapidly today, the user gets maybe a dozen steps per second because each step's TargetStoppedEvent triggers a synchronous fan-out to every widget, each of which repaints. Most of those repaints are pure waste — the user only cares about the final state once they stop holding F11.

Proposed change

Two pieces:

1. Mark-dirty in callbacks; render on a timer

Each widget that consumes "snapshot"-style events (target stopped, register changed, active thread changed — anything where only the latest matters) does the following in its event callback:

void RegisterWidget::onDebuggerEvent(const DebuggerEvent&) {
    m_dirty = true;
    // do not call update() or repaint or fetch state here
}

A QTimer running at ~10Hz (every 100ms) checks the dirty flag and, if set, fetches the current state and triggers update():

void RegisterWidget::onFrameTick() {
    if (!m_dirty) return;
    m_dirty = false;
    m_snapshot = m_controller->GetState()->GetRegisters();
    update();
}

1000 events arrive between two timer ticks → dirty flipped 1000 times → one repaint with the freshest state.

2. Per-widget audit for snapshot vs. transition semantics

Not every event is "snapshot" semantics. Things like BreakpointChangedEvent are transitions (each one mutates a list; coalescing would lose information). Audit each widget and apply the dirty-bit pattern only to the snapshot subscribers; leave transition handlers running inline.

Suggested classification (verify per-widget):

Widget Snapshot or transition? Treatment
Register view, stack view, IP highlight, locals, statusbar snapshot (cares about latest state) dirty-bit + 100ms timer
Module list mostly transition but rarely changes during run dirty-bit + timer fine (low rate)
Thread frames snapshot dirty-bit + timer
Breakpoint widget transition inline (low rate already)
TTD events / bookmarks append/transition inline
Stdout pane append inline + Qt's own buffering

Why 100ms

It's slow enough that 1000 events coalesce into ~10 repaints (back-of-envelope), fast enough that the user perceives the updates as live. A perfect setting may be 50–150ms depending on widget cost; configurable per-widget if needed.

What this enables

Combined with Step(count=N) batching at the controller level (separate proposal), users holding F11 would see the engine actually run at engine speed — limited by adapter step latency rather than UI repaint cost. The two are complementary:

  • Step(count=N) collapses N user steps into one engine session, reducing the number of events fired.
  • The dirty-bit pattern ensures that when events DO fire rapidly (for any reason, not just stepping — also during target activity bursts like rapid module loads), the UI doesn't lag indefinitely behind.

Out of scope

  • Changing the event model / dispatcher contract (covered in earlier discussions). This proposal is purely on the widget consumer side.
  • Coalescing inside the broadcast queue (would require classifying events at the controller level; nice but bigger).
  • Snapshot-pointer / "always-fresh" rendering for high-rate widgets (would bypass events entirely; only worth doing if 100ms still isn't responsive enough).

Estimated scope

Each widget that opts in is ~15 lines: a member dirty flag, a QTimer, a slot. There are ~10 candidate widgets in ui/. Could land as one widget per PR or all in one focused refactor — they're independent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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