[PR #21880] [MERGED] perf: cache KaTeX module import as singleton across all renderer instances #65173

Closed
opened 2026-05-06 10:56:46 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/21880
Author: @Classic298
Created: 2/25/2026
Status: Merged
Merged: 2/26/2026
Merged by: @tjbck

Base: devHead: perf/katex-singleton-import


📝 Commits (2)

  • f7866d3 perf: cache KaTeX module import as singleton across all renderer instances
  • 1550cc7 Update KatexRenderer.svelte

📊 Changes

1 file changed (+19 additions, -7 deletions)

View changed files

📝 src/lib/components/chat/Messages/Markdown/KatexRenderer.svelte (+19 -7)

📄 Description

KatexRenderer.svelte dynamically imports katex, mhchem, and the CSS on every component mount. When a message contains multiple math expressions, this triggers redundant module resolution for each one. Move the import promise to a module-level singleton using Svelte's context='module' script block so it loads once and is shared across all KatexRenderer instances.

this is a completely invisible change - free lunch

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.

Note

Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/21880 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 2/25/2026 **Status:** ✅ Merged **Merged:** 2/26/2026 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `perf/katex-singleton-import` --- ### 📝 Commits (2) - [`f7866d3`](https://github.com/open-webui/open-webui/commit/f7866d3f45029fd6b87520321226d7dd5ee1383a) perf: cache KaTeX module import as singleton across all renderer instances - [`1550cc7`](https://github.com/open-webui/open-webui/commit/1550cc7851c6272e240195666ece189003c3aa59) Update KatexRenderer.svelte ### 📊 Changes **1 file changed** (+19 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `src/lib/components/chat/Messages/Markdown/KatexRenderer.svelte` (+19 -7) </details> ### 📄 Description KatexRenderer.svelte dynamically imports katex, mhchem, and the CSS on every component mount. When a message contains multiple math expressions, this triggers redundant module resolution for each one. Move the import promise to a module-level singleton using Svelte's context='module' script block so it loads once and is shared across all KatexRenderer instances. <ins>**this is a completely invisible change - free lunch**</ins> ### Contributor License Agreement <!-- 🚨 DO NOT DELETE THE TEXT BELOW 🚨 Keep the "Contributor License Agreement" confirmation text intact. Deleting it will trigger the CLA-Bot to INVALIDATE your PR. --> By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. > [!NOTE] > Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-06 10:56:46 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#65173