Native all the way, until you need text

· design · Source ↗

TLDR

  • A 20-year macOS/iOS veteran tried every native text stack (SwiftUI, NSTextView, AppKit, TextKit 2) for a streaming Markdown chat UI and found WebKit or Electron unavoidable.

Key Takeaways

  • SwiftUI blocks cross-primitive text selection by design; you cannot select across a Markdown document built from SwiftUI views.
  • NSTextView with TextKit 2 solves selection but breaks SwiftUI integration and produces CPU spikes during streaming.
  • NSCollectionView cells blink on update by design, ruling it out for streaming chat.
  • Raw TextKit 2 prototypes showed acceptable perf but streaming remained broken and modern interop was absent.
  • WebKit renders Markdown with good typography and proper selection; Electron adds Git-diff rendering and matching or better perf than TextKit 2.

Hacker News Comment Review

  • Commenters split on scope: several argued WebKit is a native macOS framework and the right tool for Markdown, making the Electron leap unnecessary and overcorrected.
  • Performance claims were contested; one Qt/C++ dev showed native apps can significantly outperform web apps, pinning the blame on SwiftUI specifically rather than native development broadly.
  • Practical testing of swift-markdown-ui and its successor Textual showed real failures: p95 scroll latency of 18.86 ms and live-update p95 of 59.33 ms against a 16.7 ms budget, giving concrete evidence the alternatives are not production-ready.

Notable Comments

  • @simonw: Asked directly whether any SwiftUI Markdown library handles streaming without flickering, a question that went unanswered.
  • @dive: Benchmarked Textual; static Markdown scroll hit max 232 ms latency and live update p95 was 59 ms, both failing the 16.7 ms frame budget.

Original | Discuss on HN