Skip to content

perf(json): indent large JSON, wrap long lines faster, cancel stale JSON renders - #4427

Merged
datlechin merged 6 commits into
mainfrom
perf/json-views
Nov 23, 2026
Merged

datlechin merged 6 commits into
mainfrom
perf/json-views

Conversation

@datlechin

@datlechin datlechin commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Perf audit 2026-11-22b, lane json-views (finding 2; decisions D6, D7).

  • JV2 (2b) Word wrap of a run with no break opportunity: the punctuation test reads the UTF-16 unit first and builds the composed sequence only for whitespace, punctuation and surrogates. The CRLF check reads two units. Same breaks, pinned by a differential over every offset of 2,000 generated strings.
  • JV4 (2d) JsonReindenter: a one-pass byte writer replaces the node-tree writers, same grammar as JsonSyntaxParser. JSON is indented up to 2,000,000 characters, counted on the indented text (D6, option b). normalize covers sources up to 2,000,000.
  • JV5 (2e) Inspector JSON field: the model lives in a @StateObject (JsonFieldEditor), built once per field instead of once per parent body. An echo equal to the last synced text is refused before any parse. resolvePendingValue reuses its compact form.
  • JV6 (2f) Result View > JSON: the render runs in the view's own task, so a newer render key cancels it; the converter checks every 256 rows. No reindent when no column is JSON. The header counts the rows in the document: "50000 of 100000 rows" (D7). The 2.5 GB reserveCapacity is gone.

Numbers

Before: build/TablePro.app (9d0d481). After: Release build of this branch. Instructions, interleaved runs, medians.

Item Measure Before After
JV2 wrapline micro, 1 MiB hex token, 27 columns 36.5 G, 108.9 GB allocated 1.37 G, 99 MB
JV2 same, 60 columns 36.6 G 1.07 G
JV2 bench_json1mb line, 27 columns 19.5 G 1.15 G
JV2 bench_json1mb line, 60 columns 0.95 G 0.66 G
JV4 reindent micro, 431 KB, indented / compact 649 M / 634 M 21.4 M / 15.3 M
JV4 1.09 MB, indented / compact source returned 54 M / 38 M
JV4 2 MB, indented (stops at the cap) / compact source returned 69 M / 70 M (gate: under 200 M)
JV5 inspector row step on bench_json400k, steps 2 to 4, writer passes 2 1
JV5 same, process instructions a step 3.84 to 3.91 G 3.05 G
JV6 Result View > JSON, Next Page (steady), process instructions 2.75 G 2.33 G
JV2, JV4 with E1 inspector row step on bench_json1mb, steps 1 to 4 3.45 to 3.72 s main, 61 G 225 to 251 ms main, 7.3 G
JV5 with E1 same on bench_json400k, writer passes a step 2 1
  • The bench_json1mb row is measured on this branch merged with main after perf(editor): lay out only the first screen of a long script and keep typing cost flat #4428 (E1). E1 alone does not reach the one-line value of the before build: its cost is wrapping that one line (61 G a step), which JV2 cuts and JV4 replaces with 80,005 indented, highlighted lines that E1 lays out lazily. Plan bar: under 250 ms main (met at the median) and 5 G (not met: 7.3 G, most of it the highlighter's parse of the 1.5 MB indented text off main).
  • JV6's open on 1,000 rows is dominated by laying out 14,003 lines: 42 G before E1, 4.4 G after.

Tests changed on purpose

  • JsonReindenterTests.sizeCap: 500,001 becomes 2,000,001.

Deliberately not fixed here

  • JV1 (16a, wrap every value in the cell popover, D1): reverted. With wrapping, opening a 1 MiB cell went from 202 to 252 MB and 41.1 G to 173 to 180 MB and 45.9 G, editable or read only. A sample shows the cost is not the unwrapped layout: TextKit 2 keeps the 1 MB paragraph as one layout fragment, so at open NSTextView builds selection layers over the whole value (0.7 to 1.5 s of main) and each draw walks every line of the fragment (0.55 to 0.83 s a pass). Wrapping touches neither, so the 64 KB limit stays.
  • JV3 (2c, restyle a long line without typesetting it again): gated on Typesetter.typeset counts from quiet pass 2, which has not run.
  • bench_jsontoken in-app row step (JV2): the fixture and harness rows were not added; JV2 is measured with the wrapline micro.
  • 2a (every line laid out at open) is E1 in the editor lane.

Merge order

Test plan

  • verify.sh test on 19 suites after merging main with perf(editor): lay out only the first screen of a long script and keep typing cost flat #4428, 206 cases pass: the new and changed cases above, plus pinned TypesetterWrapLengthTests, SQLEditorLongLineScrollTests, ValueStandInThemeTests, InspectorRowChangeTests, CellEditorArrowExitTests, DataGridTextEditorPopoverTests and the rest of each touched suite.
  • CI's UI plan fails WelcomeConnectionListUITests.testTheToolbarFiltersByTagAndSearchesTheList, red on main since perf(welcome): own the toolbar and search in AppKit #4415; fix(welcome): act on the whole query when Return leaves the search field #4432 fixes it.
  • New: LineBreakCharacters against the old rule at every offset of 2,000 generated strings (lone surrogates, combining marks, Prepend, ZWJ, supplementary punctuation, CRLF); search-window edges; the byte writer against the node-tree layout over a corpus with every truncation of one document and 511 to 513 levels; one case per caller between 500,000 and 2,000,000 characters; the UTF-16 cap at its boundary; one model per field across parent bodies; a cancelled render; 50,001 rows report 50,000.

@datlechin datlechin changed the title perf(json): indent and wrap large JSON and long cell values without stalls perf(json): indent large JSON, wrap long lines and render JSON results without stalls Nov 23, 2026
@datlechin datlechin changed the title perf(json): indent large JSON, wrap long lines and render JSON results without stalls perf(json): indent large JSON, wrap long lines faster, cancel stale JSON renders Nov 23, 2026
@datlechin
datlechin enabled auto-merge (squash) November 23, 2026 08:43
@datlechin
datlechin merged commit 67b2665 into main Nov 23, 2026
11 checks passed
@datlechin
datlechin deleted the perf/json-views branch November 23, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant