Skip to content

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

Open
datlechin wants to merge 4 commits into
mainfrom
perf/json-views
Open

datlechin wants to merge 4 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
  • JV6's open on 1,000 rows stays at 42 G: the editor laying out 14,003 lines is the editor lane's E1.
  • ml8.json1mb.rowstep (JV2 and JV4 together) is measured after E1 lands, below.

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

  • Waits for the editor lane's E1 (lay out only the first band at open). Without it, the 80,005 lines JV4 makes of a 1 MB value are all laid out on each row step.

Test plan

  • verify.sh test on 19 suites, 208 cases pass: the new and changed cases above, plus pinned TypesetterWrapLengthTests, SQLEditorLongLineScrollTests, ValueStandInThemeTests, InspectorRowChangeTests, CellEditorArrowExitTests and the rest of each touched suite.
  • 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

This branch has not been deployed

No deployments
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