[GH-ISSUE #15998] app/ui: centralize theme detection and tokenize only the active theme in code blocks #87875

Open
opened 2026-05-10 06:29:36 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @matteocelani on GitHub (May 6, 2026).
Original GitHub issue: https://github.com/ollama/ollama/issues/15998

What is the issue?

Every code block in a chat message runs syntax highlighting twice — once for light mode and once for dark mode. Both results are rendered as two separate <pre> elements, and CSS hides the inactive one. On a chat with hundreds of code blocks, this doubles the Shiki processing time for no visible benefit.

There's also no centralized way to know which theme is currently active. The theme names are hardcoded as string literals scattered across files.

Why it matters
Shiki's TextMate grammar regex is the single most expensive operation during chat loading. Cutting it in half by only tokenizing the active theme has a massive impact.

Relevant log output


OS

Linux, macOS

GPU

Apple

CPU

Apple

Ollama version

No response

Originally created by @matteocelani on GitHub (May 6, 2026). Original GitHub issue: https://github.com/ollama/ollama/issues/15998 ### What is the issue? Every code block in a chat message runs syntax highlighting twice — once for light mode and once for dark mode. Both results are rendered as two separate `<pre>` elements, and CSS hides the inactive one. On a chat with hundreds of code blocks, this doubles the Shiki processing time for no visible benefit. There's also no centralized way to know which theme is currently active. The theme names are hardcoded as string literals scattered across files. **Why it matters** Shiki's TextMate grammar regex is the single most expensive operation during chat loading. Cutting it in half by only tokenizing the active theme has a massive impact. ### Relevant log output ```shell ``` ### OS Linux, macOS ### GPU Apple ### CPU Apple ### Ollama version _No response_
GiteaMirror added the bug label 2026-05-10 06:29:36 -05:00
Author
Owner

@xmddmx commented on GitHub (May 6, 2026):

High CPU usage possibly related to this? https://github.com/ollama/ollama/issues/15797

<!-- gh-comment-id:4388979873 --> @xmddmx commented on GitHub (May 6, 2026): High CPU usage possibly related to this? https://github.com/ollama/ollama/issues/15797
Author
Owner

@matteocelani commented on GitHub (May 6, 2026):

Exactly. PR #16002 reduces the overhead per render (especially when code blocks are involved), but the 'thrashing' you're seeing is a separate issue related to render frequency during streaming.
I'm already working on other fixes to address that specifically.
Thanks for the heads up!

<!-- gh-comment-id:4389197071 --> @matteocelani commented on GitHub (May 6, 2026): Exactly. PR #16002 reduces the overhead per render (especially when code blocks are involved), but the 'thrashing' you're seeing is a separate issue related to render frequency during streaming. I'm already working on other fixes to address that specifically. Thanks for the heads up!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#87875