Engineering · November 2026

Fibo’s performance gate: count retired instructions, not CPU time, and what sidebar redraws cost

While an agent prints, the window draws a frame for every line, yet the same frame’s CPU time moves 2.5x with machine load, so a gate on it either cries wolf or sleeps. Retired instructions for the same frame move less than 1% across loads, so Fibo’s gate holds them to a 15% budget on real hardware and checks a same-process ratio on CI virtual machines, which count none. With that ruler, a terminal output frame went from 74.3 M instructions to 4.52 M, most of it saved in the sidebar.

What Fibo is: a native Mac workbench for coding agents such as Claude Code and Codex, open source (MIT), written in Rust with GPUI and libghostty-vt. Sessions are in a sidebar on the left, terminals on the right. Every time an agent prints, the terminal draws a frame, so what one frame costs decides how much CPU the window takes. Install: download the DMG, or brew install --cask majiayu000/tap/fibo.

01 The problem: CPU time is not a ruler

To make "the window must not get slower" a check every PR passes, you first need a ruler that holds still. The obvious one is CPU time: draw 300 frames, take milliseconds per frame. That is how we started, and it soon turned out to follow how busy the machine was. Fibo's development machines often have several agents compiling Rust at once, with load anywhere from single digits to over a hundred.

The same build drawing the same frame took 2.5 times as much CPU time at load 40 as at load 6 (the probe's code comment records 1.1 ms and 2.7 ms for one frame). The cause is ordinary: on a busy machine the process lands on efficiency cores and clocks drop, so the same work takes longer. The number of machine instructions the CPU actually completed, the retired instructions, barely moves. The table puts the repository's records next to a remeasurement:

WhatConditionsCPU timeRetired instructionsSource
One window frameLoad 6 vs load 402.5x apart (1.1 / 2.7 ms)Under 1% apartPerformance guide §2; comment in cpu_probe_evidence.rs
Opening settings (median of opens 2–6)Load 45 to 72Moves with load4.86–5.03 M, does not movePerformance guide §5
Opening settings (first open, cold files)Same build, several runsMoves with load9–12 M, and moves at high loadPerformance guide §5 (so the gate does not set a line on it)
The same Python computation (measured Nov 28)Normal scheduling, load 2171.49–1.68 s34.22–34.33 billion/usr/bin/time -l, 5 runs
Same (measured Nov 28)Background priority via taskpolicy -b, load 94–1744.77–5.71 s (about 3.2–3.8x)34.70–34.95 billion (+1.1% to +2.1%)Same, 3 runs
One window frame on a GitHub macOS runnerCI VM, one main CI run on Nov 27Terminal frame 0.65 ms, full redraw 7.03 msAlways 0CI log frames-pane: … 0.00 M instructions

The last row is the second problem: GitHub's macOS runners are virtual machines with no hardware counters, so ri_instructions is always 0. An instruction-count assertion on CI compares as −100% every time, which means it always passes. The gate has to notice that case first and then measure some other way.

02 What we count: retired instructions per frame

On macOS a process can ask proc_pid_rusage how many instructions it has retired so far. Fibo's window has a module compiled only into the probe build that reads it before and after a run of frames and divides the difference by the frame count (simplified):

/// Instructions this process retired: unlike CPU time, the same work
/// counts the same on a busy machine, on an efficiency core or at a lower clock.
fn instructions() -> u64 {
    if std::env::var_os("MOORING_PERF_NO_COUNTER").is_some() {
        return 0; // take the VM's path on real hardware, to test the fallback
    }
    let mut info: libc::rusage_info_v4 = unsafe { std::mem::zeroed() };
    let ok = unsafe {
        libc::proc_pid_rusage(std::process::id() as i32,
                              libc::RUSAGE_INFO_V4, (&raw mut info).cast())
    };
    if ok == 0 { info.ri_instructions } else { 0 }
}

// One stage: draw 300 frames, report CPU time and instructions per frame
let (cpu, ins) = (cpu_secs(), instructions());
/* ...draw 300 frames... */
let per_frame = (instructions() - ins) as f64 / 300. / 1e6; // M per frame

What gets measured is fixed too. The probe runs on a generated workspace: 2000 sessions, 8 spaces, 60 terminals each bound to a session, about 45 sidebar rows, close to a long-used real install (scripts/perf-fixture.py; it calls no model and touches no user data). The window stays off screen and each stage draws 300 frames. The two that matter most:

Other stages cover scrolling a line of Chinese (frames-scroll), sidebar motion, the machine rail, the plugins page, settings pages and startup to first frame: 25 numbers in the baseline file crates/fibo-app/perf-baseline.txt.

Two ways to find the big cost

Once the number holds still, finding causes gets simpler too:

Once the view is known, sample shows where: self time in taffy::compute_flexbox_layout or line_wrapper means layout; self time in app functions and SipHash means repeated per-frame computation.

Traps in the measuring itself

TrapWhat it looked likeWhat we do now
Test data too fakeThe first workspace had no sessions bound to terminals; the sidebar was empty and nothing showed upSessions bound to terminals, quota readings in the logs
The probe dirties its fixtureEach run opened one more tab; after dozens there were 91, and the terminal frame grew from 7.8 M to 27 MOld and new builds run alternately on the same state; rebuild the fixture before reporting
Terminal frames are bimodalThe same build jumps between about 6.3 M and 7.0 MThe baseline takes the higher one
The CI image has Reduce Motion onAnimations were skipped and the gate measured a still picture; it went red 11 times in a row over thisThe probe turns it off for every stage
A locked screenNo display link, on_next_frame never fires, a real window cannot be measuredThe gate uses only the off-screen probe

03 The gate: instructions on hardware, a ratio on VMs

The gate is scripts/perf-gate.py. On CI it builds its own probe release, runs every stage and compares with the baseline. It first decides whether this machine counts instructions (every stage read more than 0, and MOORING_PERF_NO_COUNTER is not set), then takes one of two paths.

Probe: 300 frames per stage 2000-session workspace, window off screen Were instructions counted? Only if every reading is > 0 Yes: real hardware All 0: GitHub macOS VM Each count ≤ baseline +15% Terminal frame, full redraw, scroll, plugins, startup… 15% under the baseline prints "lower it" Catches slowdowns over 15% Same-process ratio ≤ 2x baseline pane-share = terminal frame ÷ full redraw Also cardplay-share, theme-share Misses slowdowns under 2x Both paths: counts and pixels, not timing A cached frame matches a fully refreshed one pixel for pixel · output draws sidebar and tabs 0 times A catch-up's own frame schedules 0 catch-ups · 0 frames requested after the focus ring fades One scrolled line shapes 1–40 CoreText runs · silent input wakes its pane 0 times Green only if all pass; red uploads the pixel diffs
The decision is at lines 156 and 285–305 of scripts/perf-gate.py. The budgets are two constants: BUDGET = 0.15 and SHARE_BUDGET = 2.0.

The VM fallback: a ratio inside one process

With no instruction count and an unsteady clock, let the machine's speed cancel itself out: measure a terminal frame and a full redraw back to back in the same process and take terminal ÷ full. If the machine is busy, both slow down and the ratio barely moves. That ratio is pane-share; the baseline is 0.12, a broken build that redraws the sidebar every frame reads 0.96, and the line is 2x the baseline. One main CI run on Nov 27 read 0.09.

Numerator and denominator have to be measured side by side. Theme frames used to be compared with a terminal frame measured separately at the start, seconds earlier; the VM sped up and slowed down in between, and the same code read theme-share anywhere from 0.73 to 2.37, going red once. Now each theme alternates with the plain look in 10 runs of 30 frames, each adjacent pair gives a ratio, and the gate takes the median.

What timing cannot catch, count

Some bugs are not about how expensive a frame is but about how many frames get drawn, or whether they are right. Those are asserted with counts and pixels, which work on a VM too:

The gate gets tested too

When the gate first went in, we built three broken versions on purpose (the first three rows) and checked each was stopped; every check added later got the same treatment. Changing the gate means doing this again:

Deliberately broken buildWhat the gate sawResult
Every terminal output notifies the whole workbench+666% instructions, sidebar redrawn every frameStopped
Sidebar does not refreshPixel differences after filter, unfilter and renameStopped
Catch-up loop15 self-triggered catch-upsStopped
Plugins page not reused (hardware)+544% instructionsStopped
Animation card twice as slow (hardware)+99% instructionsStopped
Plugins page asks for frames at rest480 requests at restStopped
Page not reused (VM mode)cardplay-share 1.08, normal 0.17–0.19Stopped
Card drawn 40 extra times (VM mode)cardplay-share 0.76Stopped
Focus ring expiry check moved back after scheduling1 extra frame after the fadeStopped
Chinese shaping from before f21658e5 (main's build)frames-scroll 39.44 M, +48.5%Stopped

Testing the gate also caught it measuring nothing, twice. The plugins-page gate's first run reported "the old paper theme is not in effect": the probe had set the light theme on the dark side, the theme never changed, and the numbers looked great. Later, CI was all green but the log showed animation cards at 0.00 ms: the probe picked the costliest animation by instructions, all zero on a VM, so it picked none. The local switch that imitates a VM only changed the gate script back then, and the probe still read instructions, so nothing showed locally. Now the switch reaches the probe and the gate asserts the time is above 0. The rule: any measurement that looks very good must assert that the thing measured actually happened.

The baseline only moves down with the code

The 15% line is relative to the baseline. If an optimization lands and the baseline stays, the gate quietly loosens. On Nov 25, frames-main and frames-railrest were 25–27% under their baselines; with a 15% budget they would have had to grow over 40% to fire, so those two checks were effectively off (#568). The fix changed only those two lines, taking the higher of two full gate runs: frames-main 55.35 → 41.32 M. It did not rewrite everything with MOORING_PERF_UPDATE=1, which would have written the other numbers' ±3–8% drift into the baseline. The gate now prints a reminder when a number is 15% under its baseline.

The gate runs on every PR that touches native code; the CI run we looked at took about 10 minutes including the build. It is not a required check for merging: main only requires Workbench Rust checks. That is why rule R7 asks whoever changes rendering to run it on real hardware.

How large projects do it

Before settling on this, we looked at how a few large open-source projects handle performance regressions (surveyed Nov 4 and recorded in §9 of the performance guide; uv's workflow rechecked on Nov 28):

ProjectWhat it measuresBlocks PRs?
pandasasv benchmarks on a dedicated machine for every merged commit, with step detection afterwardsNo; its docs say the same code on the same machine can differ noticeably
uvCodSpeed: walltime mode on a dedicated machine, plus simulation mode (simulated execution, independent of load), reported back on the PRCan
Rust compiler (rustc-perf)Default metric instructions:u; changes around 0.3% show reliably; people review the graphs weeklyHuman judgement
Zed (where GPUI comes from)CI only compiles the benchmark crateNo performance gate seen

What they share: to block a PR you need a metric independent of machine load (instruction counts or simulated execution); wall-clock time can only warn after the fact. Fibo follows that: instructions on real hardware, and with no dedicated CI machine, a same-process ratio on the VM.

04 What sidebar redraws cost

With a steady ruler, the first cut went into the sidebar. The table lists the biggest changes over three weeks, each measured as instructions per frame on the same fixture with old and new builds run alternately (M = million):

DateChangeMeasuredBefore → afterLeftCommit / PR
Nov 4Sidebar becomes a cached view; terminal output no longer lays it outTerminal output frame74.3 → 10.3 M14%b1438ae
Nov 4Counts for the title bar, tabs and status bar computed once a secondTerminal output frame8.3 → 6.3–7.0 M~80%d6dcf46b
Nov 4No horizontal flex around the column without a machine rail (fixing a regression)Full redraw130 → 75.7 M58%e0661af
Nov 4Pointing at an animation card redraws only that cardPlugins page, one playing frame78.8 → 12.4 M16%fcda810d
Nov 16One-line session rows lose a column container and get a fixed heightFull redraw105 → 57 M54%#365
Nov 16Set-aside spaces test the cheap condition first and look up a setFull redraw (3 set-aside spaces)238.6 → 61.5 M26%#365
Nov 17Shaping cache found by content, not only by rowScrolling a line of Chinese419 → 52 M12%#398
Nov 19Tab strip becomes a cached view tooTerminal output frame7.88 → 5.22 M66%#466
Nov 24Chinese runs shaped by CoreText onceScrolling a line of Chinese39.41 → 26.54 M67%#569
What is left after (grey = before, 100%; green = after) Terminal frame · cached sidebarb1438ae 74.3 → 10.3 M Full redraw · no row flexe0661af 130 → 75.7 M Animation card · one cardfcda810d 78.8 → 12.4 M Full redraw · flat rows#365 105 → 57 M Full redraw · set-aside#365 238.6 → 61.5 M Chinese scroll · by content#398 419 → 52 M Terminal frame · cached tabs#466 7.88 → 5.22 M Chinese scroll · shape once#569 39.4 → 26.5 M
Each row is normalised to its own "before" to compare the share removed; absolute sizes differ a lot (scrolling Chinese started at 419 M, the tab strip change at 7.88 M).

First cut: terminal output should not lay out the sidebar

Before Nov 3, each terminal output frame cost 74.3 M instructions. Taking pieces out showed the sidebar was 88% of it. The cause is GPUI's redraw rule: cx.notify() marks an entity and all its ancestors dirty. The pane's observer called cx.notify(), so every bit of terminal output laid out the whole workbench, sidebar included.

b1438ae wraps the sidebar in a cached view (AnyView::cached): if it is not dirty and its bounds have not changed, the last frame's drawing is reused. Pane changes now notify an empty child view, Tick; the workbench still redraws the title bar and pane titles, the sidebar does not. Other changes the sidebar shows are picked up by a catch-up within a second. Terminal frames went from 74.3 M to 10.3 M, CPU from 4.5 to 0.8 ms. On Nov 19 the tab strip became a cached view the same way, and the terminal-frame baseline went from 6.96 M to today's 4.52 M.

Caching brings a new kind of bug: the sidebar not refreshing when it should. So the same commit added redraw-check, which compares, after each step, a frame drawn without refreshing against one drawn with a forced refresh, pixel for pixel.

The cost is per row, not the number of rows

With terminal frames down, the big remaining cost was the full redraw. A sample of a real window on Nov 16 showed sidebar redraws taking about half the main thread. The first guess was too many rows, so we tried laying out only visible rows: on the fixture, laying out just the first 20 took a full redraw from 91.6 M to 91.3 M, almost nothing. Taking a piece out instead: without the 50 rows under Today, 96 M became 16.5 M, about 1.6 M a row. The cost was in each row.

The reason is the layout engine, taffy: to size a container that grows with its content, it measures what is inside several times, and each level of nesting multiplies that. A one-line session row used to be row → column container → title, space, time. #365 drops that column container for rows with a single line of text and gives them the fixed height ONE_LINE_ROW. Full redraw: 105 M → 57 M (two alternating rounds: 104.7 / 105.5 → 57.0 / 57.2). visual-check.py shots confirmed the pixels did not change.

The same PR made two pure computation cuts. Each set-aside space went through every session on every redraw, testing the most expensive condition first (which space it belongs to, by comparing paths). Ordering the conditions from cheap to expensive, starting with whether the session is open at all (most are not), took a full redraw with 3 set-aside spaces from 237 to 98 M; collecting lost_agents, the sessions cut off by a restart, into a set took it from 98 to 61.5 M. Against main: 238.6 → 61.5 M.

What was rejected is in the commits too: splitting the space label into two elements saved 3%, right-aligning the time under 2%, both below the cutoff; computing the hover tip only on hover saved about 2.5%, but the tip would read the workbench when it pops up and could crash if a render held it at that moment, so not worth it.

Back in a real window: 24.3% → 8.1%

Fixture instructions do not convert into the CPU percentage a user sees, so each round ends with a sample of a real window. One on Nov 17 found the sidebar spending 1.4 s of every 10 s rendering, 1.04 s of it asking whether 33 space folders still existed (stat). The same 33 folders take 28 µs to stat from a terminal and far longer inside the app process. #386 remembers the answer per path for 2 seconds, at the cost of showing a deleted folder up to 2 seconds late.

Together with #365, the menu bar moving to deltas (#376–#378) and the host reusing hashes for unchanged content (#388), a real window with a dozen-odd agents running went from 24.3% to 8.1% CPU across the update; per 10 seconds, full-window drawing went from 2647 to 338 ms and sidebar rendering from 1395 to 126 ms. It was a single before/after, with running sessions going from 16 to 19, so treat it as rough.

Two regressions per-frame instructions did not catch

On Nov 19 the window felt slow again. The baseline and the script had not changed. One cause was the split-pane focus ring: it scheduled the next frame before checking whether it had faded, so after fading it still asked for about 120 frames a second. Each frame was cheap; there were just endless frames. #461 checks first, then schedules, and adds a gate check that nothing is requested after the fade. Per-frame instructions only say what a frame costs; how many frames get drawn has to be counted separately.

The other was scrolling. In a real window sample, terminal shaping (shape_cell) took about 5% of the main thread (433 of 8980 samples), mostly creating new CoreText layouts. The shaping cache was keyed by row and run position, so any scroll missed everything; each Chinese character is its own run, so each line an agent printed in Chinese reshaped the screen. #398 falls back to finding a run by content (text, cell width, colour, bold and italic) in the previous frame: 419 M → 52 M per line, runs handed to CoreText 774 → 18. On Nov 24, #569 found each Chinese run was shaped twice (once at the terminal size, then again at a computed scale), although a font's glyphs do not change with size and the second pass only multiplies numbers. Shaping once and scaling while drawing took frames-scroll from 39.41 to 26.54 M (−33%); the 13 terminal rendering fixtures plus a new CJK one produced byte-identical PNGs.

05 Ten rules that came out of it

Each fix ends as a rule in §4 of the performance guide, which you read before changing the UI. They are numbered in the order they were added; R8 came before R9:

RuleIn one sentenceFrom
R1Pane changes do not notify the workbench; use adopt_pane / pane_changedTerminal frame 7x (b1438ae)
R2State the sidebar shows must notify the workbench when it changes, or it is up to a second lateA cached view that missed refreshes
R3The frame a catch-up triggered must set asked, or catch-ups schedule catch-upsBroken build: 15 in 5 s
R4Values every frame needs are not derived by scanning all sessions in render; cache by revision plus current secondframe_facts, quotas, tab names
R5Do not put big lists inside a horizontal flex; it measures the whole list againFull redraw 75 → 130 M (348d005)
R6Per-frame lookups by id use FxHashSipHash was about a tenth of a terminal frame
R7Changed rendering: run the gate on real hardware; change the baseline only there, on purpose, with the reasonA VM cannot write the baseline
R8For a small part that animates, draw it in its own small view and keep the page cachedAnimation card 79 → 12 M
R9Elements on every row avoid content-sized containers; if a height is known, fix itFull redraw 105 → 57 M
R10Filters over all sessions test cheap conditions first; tables looked up in a loop become sets first238 → 61 M

Without Fibo, in your own project: on macOS the built-in /usr/bin/time -l prints retired instructions, nothing to install (run on macOS on Nov 28):

/usr/bin/time -l ./your-bench 2>&1 | grep 'instructions retired'
#   34227777414  instructions retired

# The same work on efficiency cores: CPU time grows several times, instructions barely move
taskpolicy -b /usr/bin/time -l ./your-bench

# Counters over time: record with Instruments' CPU Counters template
xcrun xctrace record --template 'CPU Counters' \
    --output run.trace --launch -- ./your-bench

Inside your program, read ri_instructions with proc_pid_rusage(pid, RUSAGE_INFO_V4, …) as above, before and after, and subtract. Three things matter more than the tool: treat a reading of 0 as "cannot measure", not a pass; on GitHub's macOS runners it is 0, so have a fallback such as a same-process ratio; and for every check you add, build a broken version first and make sure it goes red. On Linux the matching counter is perf's instructions:u (rustc-perf's default metric); we did not run it on Linux for this post.

06 Measured on Nov 28

For this post we ran the full gate 6 times on an Apple Silicon Mac (Nov 28, 01:39–02:00, with other agents compiling; 1-minute load 30–151). Two builds took turns: new is that day's main (441231a2), old is the merge that wrote today's frames-scroll baseline (34ca0380, #569). Both were built with cargo build --release -p fibo-host -p fibo-app --features fibo-app/visual-test and run with python3 scripts/perf-gate.py target/release.

Build · runLoad at startTerminal frameFull redrawScroll a Chinese lineFirst open of pluginsGate
Baseline (written on another Mac)—4.52 M41.32 M26.55 M268.97 M—
New · 1904.10 M39.71 M31.75 M (+19.6%)356.76 M (+32.6%)Red
New · 2754.24 M39.52 M31.44 M (+18.4%)339.95 M (+26.4%)Red
Old · 11514.08 M40.11 M30.33 M (+14.2%)341.12 M (+26.8%)Red
New · 3584.13 M39.61 M31.07 M (+17.0%)343.71 M (+27.8%)Red
Old · 2304.10 M40.08 M30.34 M (+14.3%)338.48 M (+25.8%)Red
New · imitating a VM370000Ratios only; all ratios pass

The table shows instructions per frame (or per open), with the change against the baseline in brackets. CPU time over the same runs: terminal frames 0.35–0.42 ms, full redraws 2.86–3.17 ms; pane-share read 0.11–0.14 in all six runs, against a baseline of 0.12. Four things come out of it:

One more thing we saw and did not chase: in 2 of the new build's 4 runs (including the VM-mode one), the probe stopped on the 设置 › 插件 page asserting that the cached panel differed from a full refresh; the old build's 2 runs did not. Pixel checks fire on a VM too, so this is either a new intermittent bug or this machine's timing under heavy load; it needs its own reproduction.

Limits: what we have not measured

Summary: three practices