Skip to content

webui: add lazy markdown loading for improved performance#19557

Closed
shem-aleph wants to merge 1 commit into
ggml-org:masterfrom
shem-aleph:feature/lazy-markdown-loading
Closed

webui: add lazy markdown loading for improved performance#19557
shem-aleph wants to merge 1 commit into
ggml-org:masterfrom
shem-aleph:feature/lazy-markdown-loading

Conversation

@shem-aleph

Copy link
Copy Markdown

Summary

Add LazyMarkdownContent component that defers markdown rendering until messages scroll into view. This significantly improves load times for conversations with many messages.

Problem

Conversations with 500+ messages would timeout or take several minutes to load because all MarkdownContent components initialize simultaneously, each running the full remark/rehype pipeline (GFM, KaTeX, syntax highlighting, etc.).

Solution

New LazyMarkdownContent wrapper that:

  • Uses IntersectionObserver to detect when messages enter viewport
  • Shows lightweight text placeholder until visible
  • Preloads with 200px margin for smooth scrolling
  • Short messages (<200 chars) render immediately
  • Streaming messages use eager rendering (no delay)

Changes

  • LazyMarkdownContent.svelte - new component with IntersectionObserver
  • ChatMessageAssistant.svelte - uses lazy for completed, eager for streaming
  • ChatMessageUser.svelte - uses lazy loading
  • ChatMessageSystem.svelte - uses lazy loading
  • index.ts - exports new component

Testing

  • npm run check passes with 0 errors
  • Tested with conversations of varying sizes
  • Streaming still works correctly with immediate rendering

Add LazyMarkdownContent component that defers markdown rendering until
messages scroll into view. This significantly improves load times for
conversations with many messages (500+ messages would previously timeout).

Changes:
- New LazyMarkdownContent.svelte using IntersectionObserver
- ChatMessageAssistant uses lazy loading for completed messages,
  eager rendering for streaming messages
- ChatMessageUser and ChatMessageSystem use lazy loading
- Short messages (<200 chars) render immediately for responsiveness

The component shows a lightweight text placeholder until the message
enters the viewport (with 200px margin for preloading), then renders
full markdown with syntax highlighting, KaTeX, etc.
@allozaur

Copy link
Copy Markdown
Contributor

Let's come back to this after we have #18655 merged which should be very soon :)

@allozaur

Copy link
Copy Markdown
Contributor

Superseded by #20999

@allozaur allozaur closed this Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants