Skip to content

[Bug] Unsloth Desktop Large Codeblocks Causes Lots of Lag in Interface #10769

Closed

Description

@FatheredPuma81

Environment

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:

  1. Have any LLM output something like such as a "Fully featured Flappy Bird clone in HTML"
  2. Do the same thing using the same but tell it not to output to a Codeblock
  3. 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.

Diagnostics and logs

N/A?

Additional context

2026-09-10.21-39-42-1.mp4

Activity

  1. added
    feature request
    on Sep 11, 2026
  2. FatheredPuma81 commented on Sep 11, 2026

    @FatheredPuma81
    Author

    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.

  3. danielhanchen commented on Sep 21, 2026

    @danielhanchen
    Member

    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.

  4. FatheredPuma81 commented on Sep 21, 2026

    @FatheredPuma81
    Author

    But that doesn't seem to explain why the lag persists even in days old chats that contain even just a single large codeblock?

  5. FatheredPuma81 commented on Sep 26, 2026

    @FatheredPuma81
    Author

    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?

  6. danielhanchen commented on Oct 12, 2026

    @danielhanchen
    Member

    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.

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

Metadata

Metadata

Assignees

Labels

bugfeature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions