perf(ui): tighten Shiki highlight caches and parallelize fences

Use content fingerprints instead of full source as cache keys, record
entry sizes once (no TextEncoder/JSON.stringify on get/evict), and
highlight multiple markdown fences concurrently.

Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com>
This commit is contained in:
Serhii Dziupin
2026-08-11 13:23:43 +00:00
co-authored by Serhii Dziupin
parent 6ab12fdb61
commit c3c47e8956
6 changed files with 205 additions and 149 deletions
@@ -1117,18 +1117,14 @@ const SimpleMarkdownRendererImpl: React.FC<{
const syntaxVars = React.useMemo(() => getMarkdownSyntaxVars(currentTheme), [currentTheme]);
const ctx = useDecorateContext(currentTheme, false, undefined, mermaidControls);
// Content-addressed render cache (see markdownCore) ignores this string for
// lookup; keep a stable per-content key so effect deps stay aligned with text.
const cacheKey = React.useMemo(
() => `simple:${variant}:${renderedContent.length}:${renderedContent.slice(0, 64)}`,
[variant, renderedContent],
);
useMorphdomMarkdown({
containerRef,
text: renderedContent,
streaming: false,
cacheKey,
// Identity is unused for cache lookup (content-addressed in markdownCore);
// keep a stable per-variant key for effect deps alongside `text`.
cacheKey: `simple:${variant}`,
syntaxVars,
ctx,
});