Problem#
Opening a thread on mobile spends ~570–750 ms in redundant remark / micromark parses, repeated per-row label translations, and a post-layout double-render in MobileEnrichedMarkdownText:
- Repeated full-document parses:
markdownDocument.ts re-parses the same message through remark-parse + remark-gfm across markdownImageSources, markdownForNativeParsing, markdownWithInlineFileLinks, markdownWithFileEmbeds, and markdownWithTableBreaks, and parses again whenever a thread is reopened or a virtualized row remounts.
- Per-row static label recomputation: Every mounted
MobileEnrichedMarkdownText calls gt() 17 times for identical static accessibilityLabels and selectionMenuConfig strings (~1,190 calls on a 70-row thread).
- Post-layout double-render + Android
RECREATE_SEGMENTS: Every message with links mounts with parsedLinkUrls = [] (linkVariants = {}, linkPillContent = {}), renders natively once, then receives onLinksChange in useLayoutEffect and re-renders with populated linkVariants / linkPillContent. On Android, EnrichedMarkdown.setMarkdownStyle and setLinkPillContent mark DirtyFlag.RECREATE_SEGMENTS + DirtyFlag.FORCE_HEIGHT, tearing down and recreating every native segment view and forcing a second Yoga + LegendList measurement pass. The same double-render also happens when LegendList recycles a row for a different markdown string.
Change#
- Added
apps/mobile/src/lib/markdownParseCache.ts with bounded LRU caches for:
- read-only
mdast ASTs (getCachedMarkdownAst, 192 entries, ≤128 KB) wired into apps/mobile/src/lib/markdownDocument.ts (parseMarkdownAst exported for reuse),
- single-pass native markdown preprocessing (
getCachedNativeMarkdown, 256 entries) used by MobileEnrichedMarkdownText when !fileEmbedLabel or the message has no 
Minimal · up to
47d1aThis change caches Markdown parsing and link extraction to speed up opening mobile threads. The earlier performance concern about scanning long text for email-like strings has been addressed with a linear-time check. No remaining merge-blocking risk was found.
Pre-merge checks:
4
Full details: Title check
Explanation
The title "perf(mobile): cache markdown AST/transforms and render-1 link URLs" names the main change: bounded LRU caches for Markdown ASTs, native Markdown preprocessing, and render-1 link URL seeding in the mobile Markdown renderer. It follows conventional commit form and matches the changeset and objectives, though it omits the label-sharing change.
Full details: Description check
Explanation
The description follows the template sections (Problem, Change, Scope, Verification) and fills each one with specific detail. It names the affected files, explains the performance problem with measured figures, and reports device measurements and checks run. Minor gaps: the Scope section does not link an issue or explain why no issue exists, the template's agent-model footer is replaced by a 'Written with Gemini 4 Neon' line, and the iOS build was not run (stated as a gap). These are non-critical, so the description is mostly complete.
Finishing Touches
Generate unit tests (beta)
479013bb-ac56-486c-a442-f6ca1944d44bReviewing files that changed from the base of the PR and between 92d6f168470318e234ef0ae0adef6c80bc2c5d2a and 47d1a92ff5f70ded8dead50fed4badd7cf8fdf6e.
apps/mobile/src/lib/markdownParseCache.test.tsapps/mobile/src/lib/markdownParseCache.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.