You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Unsloth Desktop Large Codeblocks Causes Lots of Lag in Interface #10769
Where are you using Unsloth?
Unsloth Desktop Application
Operating system and version:
Windows 11 25H2 GPU model(s) and accelerator backend:
Nvidia CUDA on RTX 4090
Versions:
Unsloth Version v0.1.808-beta
Package Version 2026.9.4
Desktop App Version 0.1.808-beta
llama.cpp Version b10840-mix-d5c17a0
What happened?
Steps to reproduce:
Have any LLM output something like such as a "Fully featured Flappy Bird clone in HTML"
Do the same thing using the same but tell it not to output to a Codeblock
Compare the two you should notice that the one with a large codeblock is nearly unusable. If it doesn't take several seconds then have it output the code again.
Expected behavior:
Little lag Actual behavior:
Lota of lag Model and operation involved:
Model and operation agnostic.
Root cause: while a large code block streams, the fence's whole token array is mapped to React elements on every frame. Streamdown's code body memoizes on result identity and our Shiki plugin returns a fresh result object on every call, so a 140K character block was rebuilding roughly fifty to seventy thousand elements about sixty times a second. The tokenizer itself was already incremental and was not the problem.
The fix keeps syntax highlighting rather than dropping it: one memoized component per line, so a growing fence only re-renders its tail, plus a line window on very large fences where off-screen lines render as plain text and the lines you are actually looking at stay coloured. The text stays in the document either way, so Ctrl+F, select-all, copy and print are unaffected.
Measured at 4x CPU throttle: twice as many lines rendered in the same wall clock, median frame back at the vsync floor, and 98% fewer mounted spans.
Worth noting your Canvas workaround pointed at the same thing: Canvas helps because it takes the code out of the thread's DOM, which is exactly the cost this removes.
Update as of latest build:
Code generation in Codeblock: Extremely laggy. Possibly worse than before?
After codeblock generation: Collapses into a Canvas even if Canvas is disabled.
Putting 10k tokens worth of randomly generated stories into a codeblock: No lag during or after, no collapse into canvas.
Fixed! Sorry on the delay. Long chats with big code blocks were re-rendering and re-highlighting code that was nowhere near the screen, and some page-wide styling made every scroll and menu open more expensive as the chat grew. #13255 now only renders and colours what is near the viewport, so scrolling, streaming and opening menus stay smooth in long chats while code keeps its syntax highlighting.
To update: Unsloth Desktop will have an update banner. For Studio, use unsloth studio update. For Docker, use docker exec <container> unsloth-studio-update. Reopen if it still happens.
Activity
FatheredPuma81 commentedon Sep 11, 2026
Oh and for anyone else who might find this enable Canvas. It hides the code and puts it in its own box which solves the problem in a round about way.
danielhanchen commentedon Sep 21, 2026
Opened #11423 for this.
Root cause: while a large code block streams, the fence's whole token array is mapped to React elements on every frame. Streamdown's code body memoizes on result identity and our Shiki plugin returns a fresh result object on every call, so a 140K character block was rebuilding roughly fifty to seventy thousand elements about sixty times a second. The tokenizer itself was already incremental and was not the problem.
The fix keeps syntax highlighting rather than dropping it: one memoized component per line, so a growing fence only re-renders its tail, plus a line window on very large fences where off-screen lines render as plain text and the lines you are actually looking at stay coloured. The text stays in the document either way, so Ctrl+F, select-all, copy and print are unaffected.
Measured at 4x CPU throttle: twice as many lines rendered in the same wall clock, median frame back at the vsync floor, and 98% fewer mounted spans.
Worth noting your Canvas workaround pointed at the same thing: Canvas helps because it takes the code out of the thread's DOM, which is exactly the cost this removes.
FatheredPuma81 commentedon Sep 21, 2026
But that doesn't seem to explain why the lag persists even in days old chats that contain even just a single large codeblock?
Studio: keep a streaming code fence highlighted, and window its spans (…
FatheredPuma81 commentedon Sep 26, 2026
Update as of latest build:
Code generation in Codeblock: Extremely laggy. Possibly worse than before?
After codeblock generation: Collapses into a Canvas even if Canvas is disabled.
Putting 10k tokens worth of randomly generated stories into a codeblock: No lag during or after, no collapse into canvas.
Not sure if I should close this or?
Studio: keep a streaming code fence highlighted, and window its spans (…
danielhanchen commentedon Oct 12, 2026
Fixed! Sorry on the delay. Long chats with big code blocks were re-rendering and re-highlighting code that was nowhere near the screen, and some page-wide styling made every scroll and menu open more expensive as the chat grew. #13255 now only renders and colours what is near the viewport, so scrolling, streaming and opening menus stay smooth in long chats while code keeps its syntax highlighting.
To update: Unsloth Desktop will have an update banner. For Studio, use
unsloth studio update. For Docker, usedocker exec <container> unsloth-studio-update. Reopen if it still happens.