Our desktop cockpit is an Electron application for watching and steering a fleet of Claude Code agent sessions that run across several subscription accounts at once. It shows session output in xterm terminals and keeps accounting of their scrollback. This note covers one change to that accounting and the measurement taken for it.

What changed in the scrollback accounting?

Before the change, scrollback accounting used a per-write recount, so each write into the terminal triggered a fresh count. After the change, the accounting is O(1). This note concerns only that accounting change. It makes no statement about rendering, the terminal library, or any other part of the application.

Why is a per-write recount expensive?

In general, a recount scales with the total amount of state being counted, not with the size of the write that triggered it. When small writes arrive often against a large buffer, each write pays for the whole buffer just to account for a few new characters. A constant-time update instead adjusts a running value from the incoming delta, which removes the dependence on buffer size. That is the general shape of this class of problem. It is offered as background, not as a diagnosis of the internals of our implementation.

How much did O(1) accounting save?

MeasurementValue
Measured cost before (per-write recount)9405ms
Measured cost after (O(1) accounting)5.4ms
Speedup1741x

The rounded figure of roughly 1700x comes from the 1741x ratio. A gap that large between two implementations of the same bookkeeping is a reminder that an accounting routine can carry real cost. Code like this is easy to treat as negligible because it is not the feature itself.

What does this measurement not tell you?

The recorded result consists of a before figure, an after figure, and their ratio. It does not record:

Because of these gaps, the ratio should not be read as the accounting's share of total terminal work. It also should not be read as a multiplier you can expect on other workloads. It shows how the two accounting approaches compared under the conditions that were measured.

Why should multi-session tools pay attention to per-write costs?

A tool built to show many terminals side by side multiplies whatever each terminal does per write. A routine that looks harmless when one terminal runs it can deserve a second look once dozens of terminals run it at the same time. This is a design consideration for that class of tool. It is not a measured finding about how our cockpit behaves under load.

How should you audit your own terminal and log views for this?

The practical lesson is to treat accounting code as a first-class candidate for profiling rather than an afterthought. A recount that runs on every write is worth questioning wherever it appears.