Files
oh-my-pi/packages
cognitive dd7357ec0d perf(tui): hoist Markdown render cache to module-level LRU
Per-instance #cachedLines is always cold when session-tree navigation
creates a fresh Markdown component. nativeHighlightCode (sync Rust FFI
in theme.ts) runs on every code block at every re-render for every new
instance, which dominates render cost during rapid navigation.

Add a module-level ordered-Map LRU (256 entries) keyed on:
  normalizedText + width + paddingX + paddingY + codeBlockIndent
  + objectId(theme) + objectId(defaultTextStyle)

Theme identity uses a WeakMap<object,number> ID so GC can collect
orphaned themes without leaking. The per-instance #cachedLines field
is kept as L1 (fastest path for repeated renders of the same instance).
L2 is checked on L1 miss and populated on first render so subsequent
distinct instances with identical inputs skip marked.lexer + FFI entirely.

Output is byte-identical to the old code (cache is invisible to callers).
New test: two distinct Markdown instances with the same (text,width,theme)
invoke highlightCode exactly once total.
2026-04-27 03:34:03 +00:00
..
2026-04-27 02:55:26 +02:00
2026-04-27 02:55:26 +02:00
2026-04-27 02:55:26 +02:00
2026-04-27 02:55:26 +02:00
2026-04-27 02:55:26 +02:00