Skip to content

perf(redis): page keys with a saved scan cursor and overlap the pipelines #4549

Done

Description

@datlechin

Problem

  • Every key-browse page, refresh and filter change scans the keyspace again from cursor 0, up to 10,000 keys, sorts them and then slices the page. With a selective MATCH on a large keyspace that is many SCAN round trips before the first page. Keys past the first 10,000 cannot be reached at all, a limit the user did not choose.
  • A grid page reads up to 64 KB of every string key for a one-line preview: a 1,000-key page of large values moves and holds up to about 64 MB.
  • A streamed scan or export takes about 11 round trips per 1,000 keys: about 9 minutes per 1M keys at 50 ms RTT (estimate from the round-trip count).
  • On a cluster, a pipeline that spans several masters is sent to them one after another, so each page's two pipelines cost N round trips each on N masters.

Cause

  • executeKeyBrowse calls scanAllKeys(maxKeys: 10_000), deduplicates through a Set and slices [offset, offset + limit) (apple/Plugins/RedisDriverPlugin/RedisPluginDriver+Scan.swift:42-68). scanAllKeys walks from RedisClusterCursor.start with COUNT up to maxKeyBrowseScan and sorts the keys (:13-40, apple/Plugins/RedisDriverPlugin/RedisPluginDriver.swift:40). Nothing keeps the cursor between pages.
  • buildKeyBrowseResult passes RedisStringPreview.byteLimit (65,536, apple/Packages/TableProCore/Sources/TableProRedisCore/RedisStringPreview.swift:5) as the string limit (apple/Plugins/RedisDriverPlugin/RedisPluginDriver+ResultBuilding.swift:53), so each string key becomes GETRANGE key 0 65535 (apple/Packages/TableProCore/Sources/TableProRedisCore/RedisKeySummary.swift:41).
  • streamScanRows sends SCAN COUNT 1000, splits the keys into batches of keySummaryBatchSize (200, RedisPluginDriver+ResultBuilding.swift:37), and for each batch awaits a TYPE+TTL pipeline and then a length+preview pipeline (apple/Plugins/RedisDriverPlugin/RedisKeyContentsRead.swift:45-86) before the next SCAN (RedisPluginDriver.swift:581-619). streamKeyRows does the same after KEYS (:622-642).
  • RedisClusterChannel.executePipeline groups commands by node and awaits each node in turn (apple/Plugins/RedisDriverPlugin/RedisClusterChannel.swift:233-262), though each node has its own connection and queue.

Change

  • Keep a scan state per tab: database, MATCH, TYPE, cursor and the keys seen so far, deduplicated. Paint the first page as soon as the SCAN replies hold limit keys, and continue from the saved cursor when the user pages forward. Reset it on refresh or a filter change. Sort each newly loaded batch, keep the rows of pages already shown where they are, and say in the status that the order covers the loaded keys. This removes the 10,000-key ceiling, since every page is reachable by walking on.
  • Size the grid's string preview to what a cell shows (1-4 KB), mark the cell truncated from the STRLEN already fetched, and read the full value with GET when the value editor or detail pane opens it, as export already does.
  • In streams, size summary batches by keys and expected bytes like PluginRowBatcher instead of a fixed 200, and send the next SCAN in the same pipeline as the current batch's TYPE+TTL reads, so the server never waits on the client.
  • Send the per-node sub-pipelines of a cluster pipeline concurrently with a task group, then resolve MOVED and ASK replies as today.

Measure

  • Open a db tab and go to the next page on keyspaces of 10k, 1M and 10M keys, with and without a selective MATCH: time and SCAN round trips per page (MONITOR or a capture). Target: one continuation SCAN per next page instead of a rescan.
  • Bytes received for a 1,000-key page of 100 KB strings (INFO stats total_net_output_bytes delta).
  • Export 100k and 1M keys locally and at +50 ms RTT: time and round trips. Target: about 2 RTT per 1,000-2,000 keys instead of 11 per 1,000.
  • Page load on a 3-master cluster at +50 ms: (N - 1) x 2 RTT less.

Part of the performance plan.

Activity

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

    @datlechin
    MemberAuthor

    What the first PR for this issue ships, and what is left:

    • Shipped: key browse pages continue from a saved SCAN cursor (no rescan from 0, no 10,000-key ceiling for paged browsing), each load sorted on its own with the status saying so, and cluster pipelines sent to every node at once.
    • Left: sizing the grid's string preview to the cell (1-4 KB). Today a shortened string is refused for inline edit (RedisStatementGenerator.isShownInPart), and nothing reads the whole value when the value editor or detail pane opens it. A smaller preview without that read would lock every value between the new size and 64 KB. It needs a host path that reads one cell's full value on open, which this driver does not have yet.
    • Left: stream batches sized by bytes and the next SCAN sent in the same pipeline as a batch's TYPE+TTL reads. On a cluster the SCAN cursor is per node, so the pipeline cannot simply carry it; this needs its own change to streamScanRows and the cluster channel.
    • The walk is kept per database, MATCH and TYPE in the session driver, not per tab: the driver has no tab identity. Two tabs on the same scope share one walk, and the first page of either starts it over.
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