Skip to content

perf(results): read large text, json and blob cells as a head and a length #4525

Description

@datlechin

Problem

A table page fetches, decodes and keeps every text, JSON, jsonb and XML value in full, however large. The grid shows a one-line preview of each. The benchmark's big_cells table (200 rows, each with 1 MB of text) moves about 200 MB per page and holds it for the life of the tab. A query tab does the same for any result. Large binary values are deferred only on MySQL and MariaDB.

Cause

  • UnloadedValuePlan.resolve defers a column only when the engine declares a byte length function, the page selects the whole primary key, and the column's type isBlobType (apple/TablePro/Core/Services/Query/UnloadedValuePlan.swift:21-40, filter at :33). isBlobType is true only for .blob (apple/TablePro/Core/Services/ColumnType.swift:147-152).
  • Only the curated MySQL and MariaDB entries set binaryLengthFunction (apple/TablePro/Core/Plugins/PluginMetadataRegistry+CuratedDefaults.swift:252, :325), and no plugin declares one. So PostgreSQL bytea, SQLite and every other engine read binary values in full too.
  • The deferred form is all or nothing: CASE WHEN length <= limit THEN col END plus a length column (UnloadedValuePlan.swift:42-57). It cannot carry a head of a long text.
  • The fold re-slices every row of the page with Array(row.prefix(start)) (UnloadedValuePlan.swift:98), and Fetch All runs it over every fetched row (apple/TablePro/Core/Coordinators/PaginationCoordinator.swift:381).
  • Each value is copied whole into a String: LibPQCellDecoding.text(from:) (apple/Plugins/PostgreSQLDriverPlugin/LibPQCellDecoding.swift:26-28) and MySQL's charset decode (apple/Plugins/MySQLDriverPlugin/MySQLColumnDecoding.swift:59-60).
  • A query tab has no deferral at all.
  • Two cutting reads already exist:
    • SQLite has a value-cutting read, readValues (apple/Plugins/SQLiteDriverPlugin/SQLitePlugin.swift:636-647). Only the iOS app calls it (apple/TableProMobile/TableProMobile/Drivers/SQLiteBackedDriver.swift:108), through PluginGridCut. The macOS grid does not.
    • The core already models a cut cell as CellTextHead { text, cut } (core/crates/ffi/src/results/result_set.rs:16, :127).

Overlaps #2490 (closed): BLOB deferral on MySQL and MariaDB for tables with a primary key is done. This issue extends it to text, JSON, jsonb and XML, and to the other engines, and replaces the all-or-nothing form with a head.

Change

  • Table tabs. For every column kind that can hold a large value (text, JSON, jsonb, XML, binary, and any type whose declared length is over the inline limit), select a head and the octet length instead of the value.
    • Each plugin declares its own prefix and length functions next to binaryLengthFunction: PostgreSQL left(col::text, N) and octet_length(col), MySQL LEFT(col, N) and LENGTH(col), SQLite substr(col, 1, N) and length(CAST(col AS BLOB)).
    • Character prefixes never cut a UTF-8 sequence.
    • The threshold is the connection's existing inline limit (binaryInlineLimitBytes).
  • The full value, on demand. A cell over the limit is marked cut with its length. Its full value is read by key through UnloadedValueReader, as BLOBs are today, when the detail pane, the editor, copy or Export Results asks for it. An edit to another cell never writes an unloaded value (Fetch BLOB values only when a cell is opened #2490's rule).
  • Query tabs, and tables without a usable key. Cut each value at decode into a head plus its octet length.
    • A full re-read is offered when the result's columnOrigins resolve the column to a base table whose primary key is in the result.
    • Otherwise the cell says it was cut at N KB and offers to run the statement again for that value.
    • On SQLite, use readValues on macOS as iOS does.
  • The fold. Compute deferred lengths while the rows are built, instead of re-slicing every row afterwards.
  • With perf(results): hold every Mac result in the core's columnar store #4521, the head and the cut flag go into the store, which already models them.

Measure

  • big_cells on PostgreSQL and MySQL: bytes received for the first page (pg_stat_statements or the socket counters), phys_footprint with the tab open, and time to first paint, before and after. Expected: kilobytes per row instead of 1 MB.
  • A table of 10,000 rows of 1 MB jsonb (PostgreSQL) and JSON (MySQL): open the table, page through it, open one cell in the detail pane. Only that cell's full value is fetched.
  • The same SELECT * in a query tab at the default row cap: phys_footprint before and after.
  • Tests cover the generated select list per engine, the on-demand read, and an edit next to a cut cell.

Part of the performance plan.

Activity

  1. added
    enhancement
    platform-macos
    on Nov 25, 2026
  2. datlechin commented on Nov 26, 2026

    @datlechin
    MemberAuthor

    The table-tab half of this ships in #4603. What is left:

    • Query tabs. A query result still reads every value whole. Each driver needs to cut a value at decode into its first characters and its byte length. A full read is possible when columnOrigins resolve the column to a base table whose primary key is in the result; otherwise the cell says it was cut and offers to run the statement again.
    • SQLite readValues on macOS. The macOS grid still does not use the value-cutting read the iOS app calls through PluginGridCut.
    • The columnar store (perf(results): hold every Mac result in the core's columnar store #4521). A cut cell's first characters live beside the row in TableRows (SparseRowState.unloadedHeads), and the row itself holds NULL. Once perf(results): hold every Mac result in the core's columnar store #4521 lands, they move into the store's CellTextHead { text, cut }.
    • Measurement. Bytes per page, phys_footprint and first paint for big_cells on PostgreSQL and MySQL have not been taken yet. The generated SQL repeats each size test in the value, size and head expressions. A MySQL JSON value, and a PostgreSQL jsonb stored between an eighth of the limit and the limit, is turned into text for each one, so that cost belongs in the measurement. Computing the test once per row needs a subquery or LATERAL join in the table query builder.
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

    enhancementplatform-macos

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions