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):
Backend is extremely fast:
POST /api/session/newcompletes 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.
Frontend execution waterfall causes the delay: When the user clicks
+inboot.js($('btnNewSession').onclick):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 toGET /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.- Full sidebar sessions re-fetch & full DOM re-paint via
Suggested Improvements
- Optimistic Sidebar Insertion:
- Prepend the new blank session item directly into the sidebar DOM / local state rather than triggering a full
/api/sessionsquery and complete list rebuild.
- Prepend the new blank session item directly into the sidebar DOM / local state rather than triggering a full
- Lazy Workspace Tree Refresh:
- Defer
loadDir('.')viarequestIdleCallbackor only load when the workspace file drawer is actually visible.
- Defer
- Immediate Composer Focus:
- Clear and focus the message composer (
$('msg').focus()) immediately oncePOST /api/session/newreturns, letting sidebar and workspace reconciliation run asynchronously in the background.
- Clear and focus the message composer (
Environment
- WebUI commit:
8ac497df(origin/master) - Deployment: Standalone Python runner + Cloudflare Tunnel
- Browser: Chromium / Modern Desktop Browsers
Source: nesquena/hermes-webui