Repository navigation
Description
Summary
When a plugin registers app.slots.experimental_codeFenceRenderer, every timeline row that holds a matching fence is committed twice during a thread switch. The second commit runs the thread view's row layout effects again. Their getBoundingClientRect and offsetHeight reads force a full layout of the page, and with two panes open each read lays out both. A renderer whose component returns null costs 1.2–1.3 s of the switch below. That is almost all of what the full genui plugin still costs after we optimised its own render layer. With no fence renderer registered, the switch is as fast as with the plugin uninstalled.
Versions and environment
- bb 0.49.0 (local server, opened in Chromium), Plugin SDK 0.6.132
- Linux (WSL2)
- Two panes open (split workspace); no agent involved
Steps to reproduce
-
Make a plugin with only this
app.tsxand install it by path (bb plugin install ./fence-null --yes):import { definePluginApp } from "@get-bb/plugin-sdk/app"; export default definePluginApp((app) => { app.slots.experimental_codeFenceRenderer({ id: "fence-null", languages: ["ui"], component: () => null }); });
-
Use a thread with about 15 replies that each hold a ```ui fence, so that all of them mount on a switch (fewer than 20 top-level rows, or keep them near the end). Open a second thread beside it in a split.
-
Go to Settings, then back to the thread, several times. Record a performance trace, or watch Long Animation Frames (
PerformanceObserverwithtype: "long-animation-frame") and sumforcedStyleAndLayoutDuration. -
Remove the plugin (
bb plugin remove fence-null), reload, and repeat. The switch should get about as much faster as the tables above show. Most of the extra time is forced layout under the thread view's layout effects.
Expected vs actual
Expected: a code-fence renderer whose component returns null adds next to nothing to a thread switch.
Actual: with two panes, it adds 1.2–1.3 s to the switch, almost all of it forced layout. Medians of seven warm switches, two passes each:
Run 1: slot, overlay, no fence renderer.
| Slot | Overlay | No fence renderer | |
|---|---|---|---|
| Settled | 4,451 / 4,274 ms | 3,063 / 3,229 ms | 2,785 / 2,627 ms |
| Longest frame | 3,050 / 2,967 ms | 1,668 / 1,770 ms | 1,907 / 1,828 ms |
| Long-frame time | 4,123 / 3,966 ms | 2,803 / 2,977 ms | 2,532 / 2,407 ms |
| Forced layout | 3,782 / 3,713 ms | 2,331 / 2,476 ms | 2,041 / 1,910 ms |
The overlay draws the same 13 blocks with the same components as the slot, and it is 1.2–1.4 s faster.
Run 2: a renderer that draws nothing.
| Slot | Null renderer | No fence renderer | Uninstalled | |
|---|---|---|---|---|
| Settled | 4,792 / 4,297 ms | 4,205 / 3,936 ms | 2,998 / 2,624 ms | 2,776 / 2,696 ms |
| Longest frame | 3,259 / 2,995 ms | 3,032 / 2,904 ms | 2,121 / 1,852 ms | 1,931 / 1,896 ms |
| Long-frame time | 4,321 / 4,003 ms | 3,888 / 3,714 ms | 2,719 / 2,421 ms | 2,567 / 2,482 ms |
| Forced layout | 4,025 / 3,729 ms | 3,555 / 3,353 ms | 2,237 / 1,946 ms | 1,980 / 1,983 ms |
A null renderer is 1.2–1.3 s slower than no renderer, and 0.3–0.6 s faster than genui's real blocks. So about 80 % of the plugin's remaining switch cost is the slot itself. Nearly all of the difference is forced layout.
Evidence
How it was measured:
- Thread: 15 ```ui fences in its replies (genui blocks; each 1.1–3.5 KB). A second, ordinary thread open beside it in a split (two panes). 13 fences are mounted across the two panes on a switch.
- Each switch starts at
/settings, waits for the page to go quiet, then goes to the thread through BB's router (history.pushState+popstate, no reload). It ends when the page has been quiet for 300 ms. - One headless Chromium page per run, eight switches per run. The first switch is dropped and the table shows the median of the other seven. Each configuration ran in two passes, interleaved (A, B, C, A, B, C), on the same BB server.
- Measured from Long Animation Frames: settled time, longest frame, summed long-frame time, and summed forced layout (
forcedStyleAndLayoutDuration). - Headless Chromium draws on the CPU, so absolute times run far above a real screen's. Compare the columns with each other.
The plugin builds compared are all the same genui build, with one line in app.tsx changed:
| Build | Fence renderer |
|---|---|
| Slot | experimental_codeFenceRenderer({ id: "genui", languages: ["ui", …], component: SlotFence }) (shipped) |
| Overlay | none; the plugin finds fences in the DOM itself and portals its blocks over them (genui's pre-0.45 path) |
| Null renderer | experimental_codeFenceRenderer({ id: "genui", languages: [...], component: () => null }) |
| No fence renderer | registration removed; fences show as BB's own code blocks |
| Uninstalled | genui left out of /api/v1/plugins for that page |
Why (from BB 0.49.0's thread-detail-DObhspNc.js, minified names):
- When a code-fence renderer is registered, the markdown pipeline adds a remark plugin (
gF). Each matching fence then renders as a placeholder,div[data-code-fence-placeholder](componentwF), instead of a code block. - The placeholder's
useLayoutEffectcalls the host'sattach(offset, element). The host keeps the attachments in React state, so the call bumps that state. - The bump re-renders the message synchronously, before paint. The slot renders into a container through
createPortal, the container is moved into the placeholder (bF), and the content is wrapped in the plugin crash boundary (Ks,slotKind: "codeFenceRenderer"). Unattached content waits in a hiddendiv[data-code-fence-parking]. - Every row holding a fence therefore commits twice in the switch. The second commit runs the thread view's row layout effects again. In a CPU profile of the slot build those are the top forced-layout sites: BB's thread view
offsetHeightabout 1.1 s,getBoundingClientRectabout 1.0 s plus 0.23 s, and the virtualizer'sgetVirtualizedTopabout 0.28 s. Each read follows DOM writes, so each lays out the whole page, both panes.
The overlay avoids step 2–4: BB renders its normal code block once, and the plugin's portal sits outside BB's rows, so BB's row effects don't run again.
What you ruled out
- Not the plugin's own render: a component that returns
nullcosts about 80% of what the full plugin (genui) costs a switch. - Not the plugin being installed: with the registration removed, the switch is as fast as with the plugin uninstalled.
- Not the blocks' content: the same plugin drawing the same blocks through its own DOM overlay (no slot) is 1.2–1.4 s faster.
Suggestions
- Render the slot in the first pass. When the markdown renders the placeholder it already knows the fence's language, code and offset. It could render the portal target, or the slot component itself, directly, instead of attaching it in a layout effect and re-rendering.
- Or batch the attaches. Collect all attaches of one commit into a single host update, so a switch costs one extra commit for the thread rather than one per row.
- Keep row measurement off the re-render path. If row heights came from a
ResizeObserverrather thanuseLayoutEffectreads, a second commit would not force layout of the whole page.
Suggested priority and effort (optional)
Medium: every thread switch with fences on screen pays it while any plugin registers a fence renderer (genui does for ```ui). No workaround that keeps the supported slot.
Checks
- I reproduced this on the latest release or on
main, or I say above that I could not. (bb 0.49.0)
Related: #5268 added experimental_codeFenceRenderer.
Activity
bb-slop-cop commentedon Nov 10, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotplugins,ui,perf,partial-repro.host.updateschedules a synchronous follow-up portal commit, even for an empty renderer. The focused Profiler test fails identically in two clean checkouts of trusted main (f39378659a); all 24 existing fence-renderer tests pass.Mount timeline rows without forcing layout from the scroll handler (#…