Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: load long chat history faster on Linux by mounting parked history in larger steps (#16924)
Daniel Hane94f007e5902
diff --git a/studio/frontend/src/components/assistant-ui/message-window-controller.ts b/studio/frontend/src/components/assistant-ui/message-window-controller.tsindex 7fde7fe6dd2..6f19d672a88 100644--- a/studio/frontend/src/components/assistant-ui/message-window-controller.ts+++ b/studio/frontend/src/components/assistant-ui/message-window-controller.ts@@ -2,7 +2,7 @@// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0// Detach the stable portal target so React retains message state, refs and handlers.-const REACH = 2000;+export const REACH = 2000;const FIND_FLAG = "data-find-bar-open";const controllers = new WeakMap<HTMLElement, MessageWindowController>();diff --git a/studio/frontend/src/components/assistant-ui/progressive-messages.tsx b/studio/frontend/src/components/assistant-ui/progressive-messages.tsxindex 292731b8945..f2ebffb6516 100644--- a/studio/frontend/src/components/assistant-ui/progressive-messages.tsx+++ b/studio/frontend/src/components/assistant-ui/progressive-messages.tsx@@ -29,6 +29,7 @@ import {anchorCorrection,alignAnchorCorrection,initialWindow,+ nextMountChunk,watchProgressiveScroll,widen,} from "@/components/assistant-ui/progressive-mount-controller";@@ -37,6 +38,7 @@ import {rendersAsRow,} from "@/components/assistant-ui/thread-message-slot";import { useAdjustForContentInsertedAbove } from "@/components/assistant-ui/use-intent-aware-autoscroll";+import { REACH as WINDOW_REACH } from "@/components/assistant-ui/message-window-controller";import { inputPointerHeld } from "@/lib/input-pointer-state";import { isWebKitGTK } from "@/components/ui/theme-view-transition";@@ -180,6 +182,13 @@ type HeldAnchor = {rowSample: AnchorSample | null;};+/** Px from the viewport top up to the first mounted row's top; prepends land above it. */+function frontierAbove(viewport: HTMLElement | null): number | null {+ const first = viewport?.querySelector("[data-role][data-message-id]");+ if (!viewport || !first) return null;+ return viewport.getBoundingClientRect().top - first.getBoundingClientRect().top;+}+function isAnchorVisible(viewport: HTMLElement, element: Element): boolean {const box = element.getBoundingClientRect();const fold = viewport.getBoundingClientRect().top;@@ -269,6 +278,7 @@ function useProgressiveMountWindow(| null>(null);const idleRef = useRef<HeldAnchor | null>(null);+ const chunkRef = useRef(0);const scrollActivity = useRef<ReturnType<typeof watchProgressiveScroll> | null>(null);useEffect(() => {@@ -327,8 +337,13 @@ function useProgressiveMountWindow(return;}captureAnchor();+ // Read after the capture's layout reads, so this forces no extra layout.+ const chunk = WEBKIT_GTK+ ? (chunkRef.current = nextMountChunk(+ chunkRef.current, frontierAbove(viewportRef.current), MOUNT_CHUNK, WINDOW_REACH))+ : MOUNT_CHUNK;const commit = () => {- setMountWindow((current) => widen(current, count, MOUNT_CHUNK));+ setMountWindow((current) => widen(current, count, chunk));};// Keep the prepend and its scroll correction inside the same WebKit rendering frame.if (WEBKIT_GTK) flushSync(commit);@@ -336,7 +351,7 @@ function useProgressiveMountWindow(};frame = requestAnimationFrame(advance);return () => cancelAnimationFrame(frame);- }, [mountWindow, count, captureAnchor, isRunningNow]);+ }, [mountWindow, count, captureAnchor, isRunningNow, viewportRef]);// mountWindow is a trigger: this must run in the commit that widened the window, before paint.// biome-ignore lint/correctness/useExhaustiveDependencies: mountWindow is a trigger, see above@@ -368,6 +383,8 @@ function useProgressiveMountWindow(useEffect(() => {if (mountWindow == null) {idleRef.current = null;+ // The next thread's first steps start small again.+ chunkRef.current = 0;return;}let frame = 0;diff --git a/studio/frontend/src/components/assistant-ui/progressive-mount-controller.ts b/studio/frontend/src/components/assistant-ui/progressive-mount-controller.tsindex 33f444b2d0c..9fae807a2b0 100644--- a/studio/frontend/src/components/assistant-ui/progressive-mount-controller.ts+++ b/studio/frontend/src/components/assistant-ui/progressive-mount-controller.ts@@ -94,6 +94,29 @@ export function widen(current: MountWindow, count: number, chunk = CHUNK_MESSAGEreturn { start };}+/**+ * Largest WebKitGTK step for parked history. 32 restored the pre-windowing load time but made single+ * frames up to ~1.4 s on CPU-painted WebKit; 16 keeps the worst frame at the 2-per-step level.+ */+export const FAR_MOUNT_CHUNK = 16;++/**+ * WebKitGTK step size. Rows prepended within `reach` px above the viewport top stay unparked and can+ * move what the reader sees, so they mount `near` at a time; past that they are parked as they land,+ * so the step grows fourfold per frame up to `max` (each commit has a fixed cost there). `previous`+ * is 0 before the first step, which stays `near` so it does not delay the tail's first paint.+ */+export function nextMountChunk(+ previous: number,+ frontierAbovePx: number | null,+ near: number,+ reach: number,+ max = FAR_MOUNT_CHUNK,+): number {+ if (frontierAbovePx == null || !(frontierAbovePx > reach)) return near;+ return Math.max(near, Math.min(max, previous * 4));+}+/** Out-of-window indices are not rendered at all: hiding would not avoid the mount cost. */export function admits(current: MountWindow, index: number): boolean {return current == null || index >= current.start;diff --git a/studio/frontend/tests/progressive-mount-controller.test.ts b/studio/frontend/tests/progressive-mount-controller.test.tsindex aead9a1c7f2..ea0e5e50add 100644--- a/studio/frontend/tests/progressive-mount-controller.test.ts+++ b/studio/frontend/tests/progressive-mount-controller.test.ts@@ -18,6 +18,8 @@ import {alignAnchorCorrection,initialWindow,isCovered,+ FAR_MOUNT_CHUNK,+ nextMountChunk,stepsToCover,watchProgressiveScroll,widen,@@ -428,3 +430,41 @@ test("subpixel reflows can be absorbed without issuing fractional scroll writes"assert.equal(anchorCorrection(before, before, 1 / 64), null);assert.deepEqual(alignAnchorCorrection(-0.375, 0), { scroll: 0, inset: 0.375 });});++test("WebKitGTK steps stay small near the reader and ramp to FAR_MOUNT_CHUNK past the window reach", () => {+ const near = 2;+ const reach = 2000;+ // Unknown geometry or a frontier within reach (or below the viewport top) keeps the small step.+ assert.equal(nextMountChunk(near, null, near, reach), near);+ assert.equal(nextMountChunk(CHUNK_MESSAGES, 0, near, reach), near);+ assert.equal(nextMountChunk(CHUNK_MESSAGES, -500, near, reach), near);+ assert.equal(nextMountChunk(CHUNK_MESSAGES, reach, near, reach), near);+ assert.equal(nextMountChunk(CHUNK_MESSAGES, Number.NaN, near, reach), near);+ // Past it the first step of a window (previous 0) stays small, so the tail paints first; then it+ // grows to the cap and holds.+ const steps: number[] = [];+ let chunk = 0;+ for (let i = 0; i < 6; i += 1) {+ chunk = nextMountChunk(chunk, reach + 1, near, reach);+ steps.push(chunk);+ }+ assert.deepEqual(steps, [near, 8, FAR_MOUNT_CHUNK, FAR_MOUNT_CHUNK, FAR_MOUNT_CHUNK, FAR_MOUNT_CHUNK]);+ assert.ok(FAR_MOUNT_CHUNK <= 16, "larger far steps made ~1.4 s frames on CPU-painted WebKit");+ // A step after near ones ramps from the near size.+ assert.equal(nextMountChunk(near, reach + 1, near, reach), 8);+ // Coming back within reach (the reader scrolled up to the frontier) drops straight to the small step.+ assert.equal(nextMountChunk(CHUNK_MESSAGES, 100, near, reach), near);+ // The near step already being the cap (other engines) never changes it.+ assert.equal(nextMountChunk(CHUNK_MESSAGES, 10_000, CHUNK_MESSAGES, reach), CHUNK_MESSAGES);+ assert.equal(nextMountChunk(CHUNK_MESSAGES, null, CHUNK_MESSAGES, reach), CHUNK_MESSAGES);+ // A 300-message thread past the reach covers in about 20 commits instead of about 142.+ let current: MountWindow = initialWindow(300, false);+ let commits = 0;+ chunk = 0;+ while (current != null) {+ chunk = nextMountChunk(chunk, reach + 1, near, reach);+ current = widen(current, 300, chunk);+ commits += 1;+ }+ assert.ok(commits <= 24, `took ${commits} commits`);+});diff --git a/studio/frontend/tests/progressive-mount-glue.test.ts b/studio/frontend/tests/progressive-mount-glue.test.tsindex 82ffa1539b9..ab75b835180 100644--- a/studio/frontend/tests/progressive-mount-glue.test.ts+++ b/studio/frontend/tests/progressive-mount-glue.test.ts@@ -87,7 +87,7 @@ test("the window is only ever advanced through widen", () => {const ok =call === "null" ||call.startsWith("initialWindow(") ||- call.includes("widen(current, count, MOUNT_CHUNK)");+ call.includes("widen(current, count, chunk)");assert.ok(ok,`setMountWindow(${call}) is not one of null / initialWindow / widen`,@@ -115,7 +115,7 @@ test("the widening step is deferred and WebKit commits inside the animation framconst widening = section(GLUE,"if (mountWindow == null) return;",- "}, [mountWindow, count, captureAnchor, isRunningNow]);",+ "}, [mountWindow, count, captureAnchor, isRunningNow, viewportRef]);",);assert.match(widening,@@ -130,6 +130,23 @@ test("the widening step is deferred and WebKit commits inside the animation framassert.match(widening, /if \(scrollActivity\.current\?\.blocked\(inputPointerHeld\(\)\)\) \{\s*frame = requestAnimationFrame\(advance\);\s*return;/);});+test("only WebKitGTK sizes the step by the prepend frontier; other engines keep CHUNK_MESSAGES", () => {+ assert.match(GLUE, /const MOUNT_CHUNK = WEBKIT_GTK \? 2 : CHUNK_MESSAGES;/);+ const widening = section(+ GLUE,+ "if (mountWindow == null) return;",+ "}, [mountWindow, count, captureAnchor, isRunningNow, viewportRef]);",+ );+ assert.match(+ widening,+ /const chunk = WEBKIT_GTK\s*\?\s*\(chunkRef\.current = nextMountChunk\(\s*chunkRef\.current, frontierAbove\(viewportRef\.current\), MOUNT_CHUNK, WINDOW_REACH\)\)\s*: MOUNT_CHUNK;/,+ );+ // Measured after the anchor capture, whose layout reads it reuses.+ assert.ok(widening.indexOf("captureAnchor();") < widening.indexOf("const chunk = "));+ // The near/far boundary is the window controller's own reach, not a copy of it.+ assert.match(GLUE, /import \{ REACH as WINDOW_REACH \} from "@\/components\/assistant-ui\/message-window-controller";/);+});+test("the anchor is measured against its scroll container, not against the window", () => {// getBoundingClientRect().top is window-relative, so container moves would read as insertion.assert.match(