Mermaid.js Performance Analysis
Analysis of kontask rendering slowdown and proposed fix
Output
📊 Mermaid.js Performance Analysis
Good News
CLAUDE.md is already clean! The Mermaid documentation was already extracted to docs/MERMAID-GUIDE.md (204 lines). CLAUDE.md only has a single reference line:
📚 Diagram Guide: See docs/MERMAID-GUIDE.md for Mermaid.js diagrams.
⚠️ The Real Problem
The slowdown is caused by eager loading of Mermaid.js in konui/src/views/layout.ts:1435:
<script src="https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js"></script>
| Issue | Impact |
|---|---|
| Synchronous load in <head> | Blocks page render |
| ~1.5MB library size | Slow on mobile/slow networks |
| Loads on every page | Wasted bandwidth when unused |
| Most kontasks don't use diagrams | Unnecessary overhead |
💡 Proposed Fix: Lazy Loading
Instead of loading Mermaid on every page, load it only when a diagram is actually requested:
// Remove sync script from <head> // Replace with lazy-loading function: window.renderMermaidDiagram = async function(elementId, definition) { // Lazy load mermaid only when first diagram is requested if (!window.mermaid) { await loadScript('mermaid@11'); mermaid.initialize({ /* config */ }); } // Then render... };
📈 Expected Improvement
| Metric | Before | After |
|---|---|---|
| Initial page load | +1.5MB (blocking) | 0 KB |
| Kontask cards (no diagrams) | Delayed | Instant |
| First diagram render | Instant | +200ms (one-time load) |
Summary
Your instinct was right about Mermaid being the culprit, but the fix is in the loading strategy, not CLAUDE.md (which is already clean). I recommend implementing lazy loading - this will make 95%+ of kontask cards render instantly while only adding a small delay for the rare cards that actually use diagrams.
The other interactive components (SimpleChart, Timeline, SearchableList, FileTree, StepThrough) are all inline JavaScript that execute on-demand, so they don't cause the same blocking issue.
Quick Actions
Original Request
No layout configured
Details
Raw Data
{
"id": "1f892910-5105-47f4-840a-38fe3c60a559",
"type": "general",
"status": "completed",
"title": "Mermaid.js Performance Analysis",
"description": "Analysis of kontask rendering slowdown and proposed fix",
"context": {
"output": "<div style=\"background:#1e1e1e;color:#e0e0e0;padding:20px;border-radius:8px;font-family:'Consolas','Monaco',monospace;\">\n<h2 style=\"font-family:sans-serif;color:#fff;margin:0 0 16px 0;\">📊 Mermaid.js Performance Analysis</h2>\n\n<h3 style=\"font-family:sans-serif;color:#98c379;margin:16px 0 8px 0;\">Good News</h3>\n<p style=\"line-height:1.6;\">CLAUDE.md is already clean! The Mermaid documentation was already extracted to <code style=\"background:#2d2d2d;padding:2px 6px;border-radius:4px;\">docs/MERMAID-GUIDE.md</code> (204 lines). CLAUDE.md only has a single reference line:</p>\n<pre style=\"background:#2d2d2d;padding:12px;border-radius:6px;overflow-x:auto;\"><span style=\"color:#7f848e;\">📚 Diagram Guide: See docs/MERMAID-GUIDE.md for Mermaid.js diagrams.</span></pre>\n\n<h3 style=\"font-family:sans-serif;color:#e5c07b;margin:16px 0 8px 0;\">⚠️ The Real Problem</h3>\n<p style=\"line-height:1.6;\">The slowdown is caused by <strong>eager loading</strong> of Mermaid.js in <code style=\"background:#2d2d2d;padding:2px 6px;border-radius:4px;\">konui/src/views/layout.ts:1435</code>:</p>\n<pre style=\"background:#2d2d2d;padding:12px;border-radius:6px;overflow-x:auto;line-height:1.6;\"><span style=\"color:#c678dd;\"><script</span> <span style=\"color:#e5c07b;\">src=</span><span style=\"color:#98c379;\">\"https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js\"</span><span style=\"color:#c678dd;\">></script></span></pre>\n\n<table style=\"width:100%;border-collapse:collapse;margin:16px 0;\">\n<tr style=\"background:#2d2d2d;\">\n<th style=\"padding:8px 12px;text-align:left;border-bottom:1px solid #4b5563;\">Issue</th>\n<th style=\"padding:8px 12px;text-align:left;border-bottom:1px solid #4b5563;\">Impact</th>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border-bottom:1px solid #333;\">Synchronous load in <head></td>\n<td style=\"padding:8px 12px;border-bottom:1px solid #333;\"><span style=\"color:#ef4444;\">Blocks page render</span></td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border-bottom:1px solid #333;\">~1.5MB library size</td>\n<td style=\"padding:8px 12px;border-bottom:1px solid #333;\"><span style=\"color:#ef4444;\">Slow on mobile/slow networks</span></td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border-bottom:1px solid #333;\">Loads on every page</td>\n<td style=\"padding:8px 12px;border-bottom:1px solid #333;\"><span style=\"color:#ef4444;\">Wasted bandwidth when unused</span></td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;\">Most kontasks don't use diagrams</td>\n<td style=\"padding:8px 12px;\"><span style=\"color:#ef4444;\">Unnecessary overhead</span></td>\n</tr>\n</table>\n\n<h3 style=\"font-family:sans-serif;color:#61afef;margin:16px 0 8px 0;\">💡 Proposed Fix: Lazy Loading</h3>\n<p style=\"line-height:1.6;\">Instead of loading Mermaid on every page, load it <strong>only when a diagram is actually requested</strong>:</p>\n\n<pre style=\"background:#2d2d2d;padding:12px;border-radius:6px;overflow-x:auto;line-height:1.6;\"><span style=\"color:#7f848e;\">// Remove sync script from <head></span>\n<span style=\"color:#7f848e;\">// Replace with lazy-loading function:</span>\n\n<span style=\"color:#c678dd;\">window</span>.renderMermaidDiagram = <span style=\"color:#c678dd;\">async function</span>(elementId, definition) {\n <span style=\"color:#7f848e;\">// Lazy load mermaid only when first diagram is requested</span>\n <span style=\"color:#c678dd;\">if</span> (!<span style=\"color:#c678dd;\">window</span>.mermaid) {\n <span style=\"color:#c678dd;\">await</span> loadScript(<span style=\"color:#98c379;\">'mermaid@11'</span>);\n mermaid.initialize({ <span style=\"color:#7f848e;\">/* config */</span> });\n }\n <span style=\"color:#7f848e;\">// Then render...</span>\n};</pre>\n\n<h3 style=\"font-family:sans-serif;color:#c678dd;margin:16px 0 8px 0;\">📈 Expected Improvement</h3>\n<table style=\"width:100%;border-collapse:collapse;margin:16px 0;\">\n<tr style=\"background:#2d2d2d;\">\n<th style=\"padding:8px 12px;text-align:left;border-bottom:1px solid #4b5563;\">Metric</th>\n<th style=\"padding:8px 12px;text-align:left;border-bottom:1px solid #4b5563;\">Before</th>\n<th style=\"padding:8px 12px;text-align:left;border-bottom:1px solid #4b5563;\">After</th>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border-bottom:1px solid #333;\">Initial page load</td>\n<td style=\"padding:8px 12px;border-bottom:1px solid #333;\"><span style=\"color:#ef4444;\">+1.5MB (blocking)</span></td>\n<td style=\"padding:8px 12px;border-bottom:1px solid #333;\"><span style=\"color:#22c55e;\">0 KB</span></td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;border-bottom:1px solid #333;\">Kontask cards (no diagrams)</td>\n<td style=\"padding:8px 12px;border-bottom:1px solid #333;\"><span style=\"color:#ef4444;\">Delayed</span></td>\n<td style=\"padding:8px 12px;border-bottom:1px solid #333;\"><span style=\"color:#22c55e;\">Instant</span></td>\n</tr>\n<tr>\n<td style=\"padding:8px 12px;\">First diagram render</td>\n<td style=\"padding:8px 12px;\"><span style=\"color:#22c55e;\">Instant</span></td>\n<td style=\"padding:8px 12px;\"><span style=\"color:#f59e0b;\">+200ms (one-time load)</span></td>\n</tr>\n</table>\n\n<h3 style=\"font-family:sans-serif;color:#fff;margin:16px 0 8px 0;\">Summary</h3>\n<p style=\"line-height:1.6;\">Your instinct was right about Mermaid being the culprit, but the fix is in the <strong>loading strategy</strong>, not CLAUDE.md (which is already clean). I recommend implementing lazy loading - this will make 95%+ of kontask cards render instantly while only adding a small delay for the rare cards that actually use diagrams.</p>\n\n<p style=\"color:#7f848e;margin-top:16px;\">The other interactive components (SimpleChart, Timeline, SearchableList, FileTree, StepThrough) are all inline JavaScript that execute on-demand, so they don't cause the same blocking issue.</p>\n</div>",
"requestedAt": "2026-01-09T12:00:00Z",
"requestId": "8d05e883-71ae-4de6-af1c-f6c0fd0eb987",
"choices": [
{
"label": "Implement lazy loading",
"value": "Implement lazy loading for Mermaid.js in konui/src/views/layout.ts - remove the synchronous script tag and load mermaid only when renderMermaidDiagram is called",
"primary": true
},
{
"label": "Remove Mermaid entirely",
"value": "Remove Mermaid.js support entirely from konui and update CLAUDE.md to remove the MERMAID-GUIDE.md reference"
},
{
"label": "Keep as-is",
"value": "Keep the current Mermaid loading approach - the performance impact is acceptable"
}
],
"turnTiming": {
"totalMs": 204719,
"ttfeMs": 162,
"thinkingMs": 204554,
"toolExecutionMs": 0,
"toolCallCount": 0,
"thinkingPct": 100,
"toolsPct": 0,
"ttfePct": 0
}
},
"createdBy": "claude",
"createdAt": "2026-01-08T15:56:43.190Z",
"updatedAt": "2026-01-08T15:56:50.450Z",
"requestId": "8d05e883-71ae-4de6-af1c-f6c0fd0eb987",
"scope": "vibetools",
"tags": [
"kontasks",
"performance",
"ui"
],
"targetUser": "claude"
}