Skip to content

Switching between threads takes 2-9s #4396

Open

Description

@jyc

Summary

Maybe the threads are too long? Closing the markdown file pane on the right sped things up a little, but it still takes multiple seconds.

Trace-20260925T223104.json.gz

Versions and environment

Steps to reproduce

  1. chat a lot in a thread
  2. click on another thread
  3. observe that it takes multiple seconds to load

Expected vs actual

expected: does not take multiple seconds to switch threads
actual: it does

Evidence

No response

What you ruled out

No response

Suggested priority and effort (optional)

No response

Checks

  • I reproduced this on the latest release or on main, or I say above that I could not.
  • I searched open and closed issues for the same problem.
  • If an agent wrote this, the body ends with > AGENT GENERATED and links the thread or report.

Activity

  1. jyc commented on Sep 26, 2026

    @jyc
    Author

    Committing a bunch of untracked files might have helped? I feel like I ran into this once before

  2. bborn commented on Sep 27, 2026

    @bborn

    I profiled this on an optimized build of main at a19b3ed (macOS 26, Chrome 152 headless, a 189-thread data dir snapshot) and in the trace attached above. The time is not network or server work; it is forced synchronous layout on the main thread during the switch.

    Observed

    Per switch, measured with a long-animation-frame observer and wrapped layout-read getters:

    Case Blocking time Of which forced style/layout
    Warm revisit of an already opened thread 700 to 850 ms 580 to 710 ms
    Cold open 340 to 480 ms 230 to 320 ms

    The attached Trace-20260925T223104.json.gz shows the same shape on a different machine: 965 ms of forced layout across the trace, nine main-thread tasks between 505 and 927 ms, and the top forcing callers are the timeline expandable-panel height effect (44 forced layouts, 152 ms), the secondary panel (8 forced layouts, 445 ms) and one markdown-preview measurement (202 ms).

    Causes I could confirm in code

    1. TimelineWindowedItems renders every row un-windowed on its first commits after a switch. TanStack's range is null until the scroll rect is measured, and on a keyed remount the scroll-root ref is not attached yet when the child's layout effect runs, so it flips to the fallback: and
      const renderWindow = windowingEnabled && virtualizer.range !== null;
      const indexes = renderWindow
      ? virtualItems.map((item) => item.index)
      : itemKeys.map((_, index) => index);
      . Each such commit forces a full layout of the whole timeline (110 to 120 ms each on my machine, three times per switch).
    2. ExpandablePanel reads offsetHeight and writes style.height in a layout effect that runs on mount and whenever its parent re-renders, because the effect depends on renderedBody and collapsedContent identity:
      writeHeightSync(readHeightSync(undefined));
      if (typeof ResizeObserver === "undefined") {
      return;
      }
      return observeSharedResize(target, {
      read: readHeightSync,
      write: writeHeightSync,
      });
      }, [collapsedContent, isBodyExpanded, renderedBody]);
      . With N panels in a commit that is N interleaved read/write cycles, each one a relayout.
    3. Row measurements live in a per-mount Map (
      const [windowingMeasurements] = useState(() => new Map<string, number>());
      ), so a revisit re-measures every row.

    Prototype

    bborn/bb perf/thread-switch-layout-thrash (bborn#1): seed the virtualizer with the last usable scroll-root height, keep windowing on while the ref is pending, retain measurements per thread, and only force a panel read on toggles. Same measurement after: warm revisits 200 to 240 ms blocking (107 to 130 ms forced), cold opens 230 to 250 ms (97 to 157 ms forced). Existing timeline windowing, disclosure and scroll-body tests pass (797 tests across those directories). I have not touched the secondary panel or markdown-preview callers visible in the trace.

    Ruled out

    I can split the prototype into a PR against this issue once approved per CONTRIBUTING.

    AGENT GENERATED

  3. added theissue type on Sep 30, 2026
  4. added
    ui
    on Sep 30, 2026
  5. added
    no-repro
    on Sep 30, 2026
  6. SawyerHood commented on Sep 30, 2026

    @SawyerHood
    Collaborator

    Verified scoped report: https://get-bb.github.io/reports/issues/4396.html

    NOT REPRODUCED in an optimized isolated timeline-component fixture, repeated by the same agent in two clean checkouts at the same main SHA (66 samples, 100/1,000/5,000 simple rows). All click-to-third-frame samples were below 50 ms. This is not a full-app switch measurement or an ALREADY FIXED claim: rich messages, markdown/secondary panes and the original 2–9s application delay remain unresolved. Current main includes the limited changes from #4537.

  7. wy3z commented on Nov 3, 2026

    @wy3z
    Contributor

    Note

    🤖 AGENT GENERATED: Claude analysed a DevTools trace from my machine; I reviewed it before posting.

    Reproduced on Linux desktop 0.48.1 (e003e95, Chrome 152), so after #4537.

    In a 20 s recording I switched threads 7 times. Each switch blocked the renderer for roughly 0.5 to 1 s, almost all of it forced style/layout. The server answered the timeline request in 1 to 3 ms, so the time is client-side.

    The biggest forcing callers per switch were the scroll keeper's connect/apply reading scrollTop, the TimelineWindowedItems viewport measurement, ProseMirror in the composer re-applying attributes, and useOverflowMeasurement reading scrollWidth. Each forced restyle took 20 to 40 ms.

    DevTools was open, so absolute numbers are inflated. I can't attach the trace because it contains private conversations, but I can capture another if that's useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    no-reproperfui

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions