perf(ux): "+ New Chat" has noticeable 2-3s UI freeze due to sequential full sidebar repaint, workspace loadDir, and stream teardown

Author: Arturia169Created Oct 1, 2026Updated Oct 1, 2026

Describe the bug

Clicking the + ("New Chat") button in the WebUI causes a noticeable UI latency / freeze of ~2–3 seconds before the input box settles and becomes responsive.

Analysis & Profiling

We profiled the call path across backend endpoints and frontend JavaScript (static/sessions.js, static/boot.js, static/workspace.js):

  1. Backend is extremely fast:

    • POST /api/session/new completes in ~2–10 ms locally.
    • The memory commit off the previous session (commit_session_memory) is already cleanly pushed to a daemon background thread (#5543), so the HTTP handler itself does not block.
  2. Frontend execution waterfall causes the delay: When the user clicks + in boot.js ($('btnNewSession').onclick):

    javascript
    await newSession();
    await renderSessionList();
    closeMobileSidebar();
    $('msg').focus();

    Inside newSession(), the following operations run sequentially:

    • Full sidebar sessions re-fetch & full DOM re-paint via renderSessionList(), re-parsing every conversation's badges, timestamps, and model tags.
    • Eager loadDir('.') to refresh the workspace file tree (checking git status / directories) even when the user is simply starting a fresh chat.
    • SSE connection teardown (stopSessionStream()) and re-arming to GET /api/session/stream?session_id=....

    Because these passes run sequentially and block $('msg').focus(), the UI feels sluggish and unresponsive for a few seconds on machines with dozens of sessions.

Suggested Improvements

  1. Optimistic Sidebar Insertion:
    • Prepend the new blank session item directly into the sidebar DOM / local state rather than triggering a full /api/sessions query and complete list rebuild.
  2. Lazy Workspace Tree Refresh:
    • Defer loadDir('.') via requestIdleCallback or only load when the workspace file drawer is actually visible.
  3. Immediate Composer Focus:
    • Clear and focus the message composer ($('msg').focus()) immediately once POST /api/session/new returns, letting sidebar and workspace reconciliation run asynchronously in the background.

Environment

  • WebUI commit: 8ac497df (origin/master)
  • Deployment: Standalone Python runner + Cloudflare Tunnel
  • Browser: Chromium / Modern Desktop Browsers