Skip to content

Lower the cost of many short text views #10

Open

Description

@servercimen

Problem

Each TranscriptTextView makes its own LayoutEngine, with its own serial queue (LayoutEngine.swift:76) and image store. Each view also makes a text interaction and draws into tiles. This is fine for a few long answers. A list of cards can show hundreds of short texts, and the cost in that case is not known. The benchmark measures long documents only.

Proposal

  • Add a benchmark: a scrolling LazyVStack of 200 cards, each with two or three texts of one to three lines. Measure dropped frames, memory and the time to the first layout.
  • Share one layout queue, or a small pool of queues, between views.
  • Create the text interaction, the tiles and the image store only when a view needs them.

Activity

  1. added
    enhancement
    on Nov 19, 2026
  2. servercimen commented on Nov 20, 2026

    @servercimen
    OwnerAuthor

    Status, checked on an iPhone 12 mini with main at 1afd010:

    The cost is now measured. A local version of the proposed benchmark scrolls 200 cards, each with three short Markdown texts, at 3,000 points a second for 10 s. Median of three runs:

    SwiftUI Text TranscriptText
    Dropped frames 0 0
    Main-thread CPU 3.48 s 3.95 s
    Memory peak 24 MB 39 MB

    The benchmark is not in the repository yet.

    Partly done: create things only when a view needs them.

    Not done:

    • Each view still has its own layout queue (LayoutEngine.swift:79) and its own image store.
    • A selectable view creates its text interaction at once.

    No frames drop, and the main thread does about 13% more work than with Text. So the rest of this issue is an optimization, not a problem that users see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions