@xincli/opentui-core 0.4.6 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (619) hide show
  1. package/LICENSE +21 -0
  2. package/NativeSpanFeed.d.ts +52 -0
  3. package/README.md +0 -0
  4. package/Renderable.d.ts +346 -0
  5. package/animation/Timeline.d.ts +126 -0
  6. package/ansi.d.ts +17 -0
  7. package/audio.d.ts +89 -0
  8. package/buffer.d.ts +113 -0
  9. package/console.d.ts +146 -0
  10. package/edit-buffer.d.ts +97 -0
  11. package/editor-view.d.ts +72 -0
  12. package/index-m1y9e40w.js +10045 -0
  13. package/index-m1y9e40w.js.map +32 -0
  14. package/index-sqk4ajdf.js +16121 -0
  15. package/index-sqk4ajdf.js.map +58 -0
  16. package/index.d.ts +24 -0
  17. package/index.js +11709 -0
  18. package/index.js.map +35 -0
  19. package/lib/KeyHandler.d.ts +61 -0
  20. package/lib/RGBA.d.ts +42 -0
  21. package/lib/ascii.font.d.ts +508 -0
  22. package/lib/border.d.ts +51 -0
  23. package/lib/bunfs.d.ts +7 -0
  24. package/lib/clipboard.d.ts +15 -0
  25. package/lib/clock.d.ts +15 -0
  26. package/lib/data-paths.d.ts +26 -0
  27. package/lib/debounce.d.ts +42 -0
  28. package/lib/detect-links.d.ts +6 -0
  29. package/lib/env.d.ts +42 -0
  30. package/lib/extmarks-history.d.ts +17 -0
  31. package/lib/extmarks.d.ts +90 -0
  32. package/lib/hast-styled-text.d.ts +17 -0
  33. package/lib/index.d.ts +22 -0
  34. package/lib/keybinding.internal.d.ts +33 -0
  35. package/lib/objects-in-viewport.d.ts +24 -0
  36. package/lib/output.capture.d.ts +24 -0
  37. package/lib/parse.keypress-kitty.d.ts +3 -0
  38. package/lib/parse.keypress.d.ts +27 -0
  39. package/lib/parse.mouse.d.ts +30 -0
  40. package/lib/paste.d.ts +7 -0
  41. package/lib/queue.d.ts +15 -0
  42. package/lib/render-geometry.d.ts +8 -0
  43. package/lib/renderable.validations.d.ts +12 -0
  44. package/lib/scroll-acceleration.d.ts +43 -0
  45. package/lib/selection.d.ts +64 -0
  46. package/lib/singleton.d.ts +8 -0
  47. package/lib/stdin-parser.d.ts +90 -0
  48. package/lib/styled-text.d.ts +63 -0
  49. package/lib/terminal-capability-detection.d.ts +32 -0
  50. package/lib/terminal-palette.d.ts +65 -0
  51. package/lib/tree-sitter/assets/update.d.ts +12 -0
  52. package/lib/tree-sitter/client.d.ts +65 -0
  53. package/lib/tree-sitter/default-parsers.d.ts +2 -0
  54. package/lib/tree-sitter/download-utils.d.ts +21 -0
  55. package/lib/tree-sitter/index.d.ts +7 -0
  56. package/lib/tree-sitter/parser.worker.d.ts +1 -0
  57. package/lib/tree-sitter/parsers-config.d.ts +53 -0
  58. package/lib/tree-sitter/resolve-ft.d.ts +5 -0
  59. package/lib/tree-sitter/types.d.ts +185 -0
  60. package/lib/tree-sitter/update-assets.d.ts +3 -0
  61. package/lib/tree-sitter/update-assets.js +379 -0
  62. package/lib/tree-sitter/update-assets.js.map +12 -0
  63. package/lib/tree-sitter-styled-text.d.ts +16 -0
  64. package/lib/validate-dir-name.d.ts +1 -0
  65. package/lib/yoga.options.d.ts +32 -0
  66. package/native-event-worker-repro.worker.d.ts +1 -0
  67. package/package.json +52 -74
  68. package/parser.worker.js +1399 -0
  69. package/parser.worker.js.map +20 -0
  70. package/platform/ffi.d.ts +129 -0
  71. package/platform/runtime.d.ts +14 -0
  72. package/platform/test.d.ts +12 -0
  73. package/platform/worker.d.ts +26 -0
  74. package/platform/worker.node-test.d.ts +1 -0
  75. package/plugins/core-slot.d.ts +72 -0
  76. package/plugins/registry.d.ts +42 -0
  77. package/plugins/types.d.ts +34 -0
  78. package/post/effects.d.ts +147 -0
  79. package/post/filters.d.ts +65 -0
  80. package/post/matrices.d.ts +20 -0
  81. package/renderables/ASCIIFont.d.ts +52 -0
  82. package/renderables/Box.d.ts +85 -0
  83. package/renderables/Code.d.ts +97 -0
  84. package/renderables/Diff.d.ts +147 -0
  85. package/renderables/EditBufferRenderable.d.ts +238 -0
  86. package/renderables/FrameBuffer.d.ts +16 -0
  87. package/renderables/Input.d.ts +72 -0
  88. package/renderables/LineNumberRenderable.d.ts +78 -0
  89. package/renderables/Markdown.d.ts +255 -0
  90. package/renderables/ScrollBar.d.ts +77 -0
  91. package/renderables/ScrollBox.d.ts +128 -0
  92. package/renderables/Select.d.ts +122 -0
  93. package/renderables/Slider.d.ts +47 -0
  94. package/renderables/TabSelect.d.ts +98 -0
  95. package/renderables/Text.d.ts +36 -0
  96. package/renderables/TextBufferRenderable.d.ts +107 -0
  97. package/renderables/TextNode.d.ts +92 -0
  98. package/renderables/TextTable.d.ts +154 -0
  99. package/renderables/Textarea.d.ts +65 -0
  100. package/renderables/TimeToFirstDraw.d.ts +24 -0
  101. package/renderables/__tests__/renderable-test-utils.d.ts +12 -0
  102. package/renderables/composition/VRenderable.d.ts +16 -0
  103. package/renderables/composition/constructs.d.ts +35 -0
  104. package/renderables/composition/vnode.d.ts +46 -0
  105. package/renderables/index.d.ts +23 -0
  106. package/renderables/markdown-parser.d.ts +11 -0
  107. package/renderer-theme-mode.d.ts +29 -0
  108. package/renderer.d.ts +601 -0
  109. package/runtime-plugin-support-configure.d.ts +4 -0
  110. package/runtime-plugin-support-configure.js +36 -0
  111. package/runtime-plugin-support-configure.js.map +1 -0
  112. package/runtime-plugin-support-configure.node.js +15 -0
  113. package/runtime-plugin-support.d.ts +3 -0
  114. package/runtime-plugin-support.js +5 -0
  115. package/runtime-plugin-support.js.map +1 -0
  116. package/runtime-plugin-support.node.js +15 -0
  117. package/runtime-plugin.d.ts +16 -0
  118. package/runtime-plugin.js +473 -0
  119. package/runtime-plugin.js.map +1 -0
  120. package/runtime-plugin.node.js +15 -0
  121. package/syntax-style.d.ts +61 -0
  122. package/testing/bun-test-node.d.ts +87 -0
  123. package/testing/manual-clock.d.ts +17 -0
  124. package/testing/mock-keys.d.ts +81 -0
  125. package/testing/mock-mouse.d.ts +38 -0
  126. package/testing/mock-tree-sitter-client.d.ts +27 -0
  127. package/testing/spy.d.ts +7 -0
  128. package/testing/terminal-capabilities.d.ts +7 -0
  129. package/testing/test-recorder.d.ts +61 -0
  130. package/testing/test-renderer.d.ts +54 -0
  131. package/testing/test-streams.d.ts +12 -0
  132. package/testing.d.ts +8 -0
  133. package/testing.js +1004 -0
  134. package/testing.js.map +18 -0
  135. package/tests/yoga-upstream/tools/MeasureCounter.d.ts +16 -0
  136. package/tests/yoga-upstream/tools/utils.d.ts +11 -0
  137. package/text-buffer-view.d.ts +42 -0
  138. package/text-buffer.d.ts +66 -0
  139. package/types.d.ts +175 -0
  140. package/utils.d.ts +14 -0
  141. package/yoga.d.ts +437 -0
  142. package/yoga.js +193 -0
  143. package/yoga.js.map +9 -0
  144. package/zig-structs.d.ts +256 -0
  145. package/zig.d.ts +496 -0
  146. package/dev/keypress-debug-renderer.ts +0 -148
  147. package/dev/keypress-debug.ts +0 -43
  148. package/dev/print-env-vars.ts +0 -32
  149. package/dev/test-tmux-graphics-334.sh +0 -68
  150. package/dev/test-tmux-theme-queries.sh +0 -151
  151. package/dev/thai-debug-test.ts +0 -68
  152. package/dev/theme-mode.ts +0 -290
  153. package/docs/development.md +0 -144
  154. package/prebuilt/aarch64-android/libopentui.so +0 -0
  155. package/scripts/build-android.ts +0 -226
  156. package/scripts/build-native-termux.sh +0 -525
  157. package/scripts/build.ts +0 -530
  158. package/scripts/dist-test.ts +0 -312
  159. package/scripts/package-prebuilt.ts +0 -110
  160. package/scripts/publish.ts +0 -60
  161. package/scripts/test-node-hook.mjs +0 -16
  162. package/scripts/test-node.ts +0 -241
  163. package/scripts/vendor-deps.sh +0 -73
  164. package/src/NativeSpanFeed.ts +0 -375
  165. package/src/Renderable.ts +0 -1878
  166. package/src/__snapshots__/buffer.test.ts.snap +0 -28
  167. package/src/animation/Timeline.test.ts +0 -2709
  168. package/src/animation/Timeline.ts +0 -598
  169. package/src/ansi.ts +0 -22
  170. package/src/audio.ts +0 -479
  171. package/src/benchmark/attenuation-benchmark.ts +0 -81
  172. package/src/benchmark/audio-playback-benchmark.ts +0 -344
  173. package/src/benchmark/box-draw-benchmark.ts +0 -1042
  174. package/src/benchmark/colormatrix-benchmark.ts +0 -123
  175. package/src/benchmark/gain-benchmark.ts +0 -80
  176. package/src/benchmark/latest-all-bench-run.json +0 -707
  177. package/src/benchmark/latest-async-bench-run.json +0 -336
  178. package/src/benchmark/latest-default-bench-run.json +0 -657
  179. package/src/benchmark/latest-large-bench-run.json +0 -707
  180. package/src/benchmark/latest-quick-bench-run.json +0 -207
  181. package/src/benchmark/layout-benchmark.ts +0 -2547
  182. package/src/benchmark/markdown-benchmark.ts +0 -1796
  183. package/src/benchmark/native-span-feed-async-benchmark.ts +0 -355
  184. package/src/benchmark/native-span-feed-benchmark.md +0 -56
  185. package/src/benchmark/native-span-feed-benchmark.ts +0 -596
  186. package/src/benchmark/native-span-feed-compare.ts +0 -280
  187. package/src/benchmark/render-traversal-benchmark.ts +0 -928
  188. package/src/benchmark/text-buffer-render-benchmark.ts +0 -874
  189. package/src/benchmark/text-table-benchmark.ts +0 -948
  190. package/src/buffer.test.ts +0 -292
  191. package/src/buffer.ts +0 -564
  192. package/src/console.test.ts +0 -629
  193. package/src/console.ts +0 -1253
  194. package/src/edit-buffer.test.ts +0 -1852
  195. package/src/edit-buffer.ts +0 -417
  196. package/src/editor-view.test.ts +0 -1056
  197. package/src/editor-view.ts +0 -290
  198. package/src/index.ts +0 -25
  199. package/src/lib/KeyHandler.integration.test.ts +0 -292
  200. package/src/lib/KeyHandler.stopPropagation.test.ts +0 -289
  201. package/src/lib/KeyHandler.test.ts +0 -662
  202. package/src/lib/KeyHandler.ts +0 -222
  203. package/src/lib/RGBA.test.ts +0 -60
  204. package/src/lib/RGBA.ts +0 -343
  205. package/src/lib/ascii.font.ts +0 -330
  206. package/src/lib/border.test.ts +0 -83
  207. package/src/lib/border.ts +0 -170
  208. package/src/lib/bunfs.test.ts +0 -27
  209. package/src/lib/bunfs.ts +0 -18
  210. package/src/lib/clipboard.test.ts +0 -63
  211. package/src/lib/clipboard.ts +0 -41
  212. package/src/lib/clock.ts +0 -35
  213. package/src/lib/data-paths.test.ts +0 -133
  214. package/src/lib/data-paths.ts +0 -109
  215. package/src/lib/debounce.ts +0 -106
  216. package/src/lib/detect-links.test.ts +0 -98
  217. package/src/lib/detect-links.ts +0 -56
  218. package/src/lib/env.test.ts +0 -228
  219. package/src/lib/env.ts +0 -209
  220. package/src/lib/extmarks-history.ts +0 -51
  221. package/src/lib/extmarks-multiwidth.test.ts +0 -324
  222. package/src/lib/extmarks.test.ts +0 -3547
  223. package/src/lib/extmarks.ts +0 -861
  224. package/src/lib/fonts/block.json +0 -405
  225. package/src/lib/fonts/grid.json +0 -265
  226. package/src/lib/fonts/huge.json +0 -741
  227. package/src/lib/fonts/pallet.json +0 -314
  228. package/src/lib/fonts/shade.json +0 -591
  229. package/src/lib/fonts/slick.json +0 -321
  230. package/src/lib/fonts/tiny.json +0 -69
  231. package/src/lib/hast-styled-text.ts +0 -59
  232. package/src/lib/index.ts +0 -22
  233. package/src/lib/keybinding.internal.test.ts +0 -342
  234. package/src/lib/keybinding.internal.ts +0 -182
  235. package/src/lib/objects-in-viewport.test.ts +0 -789
  236. package/src/lib/objects-in-viewport.ts +0 -153
  237. package/src/lib/output.capture.ts +0 -58
  238. package/src/lib/parse.keypress-kitty.protocol.test.ts +0 -347
  239. package/src/lib/parse.keypress-kitty.test.ts +0 -712
  240. package/src/lib/parse.keypress-kitty.ts +0 -470
  241. package/src/lib/parse.keypress.test.ts +0 -2020
  242. package/src/lib/parse.keypress.ts +0 -480
  243. package/src/lib/parse.mouse.test.ts +0 -552
  244. package/src/lib/parse.mouse.ts +0 -232
  245. package/src/lib/paste.ts +0 -18
  246. package/src/lib/queue.ts +0 -65
  247. package/src/lib/render-geometry.ts +0 -36
  248. package/src/lib/renderable.validations.test.ts +0 -87
  249. package/src/lib/renderable.validations.ts +0 -83
  250. package/src/lib/scroll-acceleration.ts +0 -98
  251. package/src/lib/selection.ts +0 -261
  252. package/src/lib/singleton.ts +0 -34
  253. package/src/lib/stdin-parser.test.ts +0 -2439
  254. package/src/lib/stdin-parser.ts +0 -2007
  255. package/src/lib/styled-text.ts +0 -178
  256. package/src/lib/terminal-capability-detection.test.ts +0 -226
  257. package/src/lib/terminal-capability-detection.ts +0 -98
  258. package/src/lib/terminal-palette.test.ts +0 -954
  259. package/src/lib/terminal-palette.ts +0 -441
  260. package/src/lib/tree-sitter/assets/README.md +0 -119
  261. package/src/lib/tree-sitter/assets/update.ts +0 -360
  262. package/src/lib/tree-sitter/assets.d.ts +0 -9
  263. package/src/lib/tree-sitter/cache.test.ts +0 -291
  264. package/src/lib/tree-sitter/client.test.ts +0 -1434
  265. package/src/lib/tree-sitter/client.ts +0 -847
  266. package/src/lib/tree-sitter/default-parsers.ts +0 -133
  267. package/src/lib/tree-sitter/download-utils.ts +0 -148
  268. package/src/lib/tree-sitter/index.ts +0 -75
  269. package/src/lib/tree-sitter/parser.worker.ts +0 -1098
  270. package/src/lib/tree-sitter/parsers-config.ts +0 -81
  271. package/src/lib/tree-sitter/resolve-ft.test.ts +0 -55
  272. package/src/lib/tree-sitter/resolve-ft.ts +0 -189
  273. package/src/lib/tree-sitter/types.ts +0 -132
  274. package/src/lib/tree-sitter/update-assets.ts +0 -10
  275. package/src/lib/tree-sitter-styled-text.test.ts +0 -1253
  276. package/src/lib/tree-sitter-styled-text.ts +0 -314
  277. package/src/lib/validate-dir-name.ts +0 -55
  278. package/src/lib/yoga.options.test.ts +0 -628
  279. package/src/lib/yoga.options.ts +0 -346
  280. package/src/native-event-worker-repro.test.ts +0 -48
  281. package/src/native-event-worker-repro.worker.ts +0 -9
  282. package/src/native-handle.test.ts +0 -221
  283. package/src/platform/ffi.test.ts +0 -516
  284. package/src/platform/ffi.ts +0 -653
  285. package/src/platform/runtime.test.ts +0 -52
  286. package/src/platform/runtime.ts +0 -121
  287. package/src/platform/test.ts +0 -45
  288. package/src/platform/worker-handler-cleanup.fixture.ts +0 -12
  289. package/src/platform/worker-onmessage-startup.fixture.ts +0 -10
  290. package/src/platform/worker-startup.fixture.ts +0 -9
  291. package/src/platform/worker.node-test.ts +0 -153
  292. package/src/platform/worker.ts +0 -425
  293. package/src/plugins/core-slot.ts +0 -579
  294. package/src/plugins/registry.ts +0 -402
  295. package/src/plugins/types.ts +0 -46
  296. package/src/post/effects.ts +0 -948
  297. package/src/post/filters.ts +0 -512
  298. package/src/post/matrices.ts +0 -288
  299. package/src/renderables/ASCIIFont.ts +0 -219
  300. package/src/renderables/Box.test.ts +0 -474
  301. package/src/renderables/Box.ts +0 -353
  302. package/src/renderables/Code.test.ts +0 -2388
  303. package/src/renderables/Code.ts +0 -555
  304. package/src/renderables/Diff.regression.test.ts +0 -381
  305. package/src/renderables/Diff.test.ts +0 -3212
  306. package/src/renderables/Diff.ts +0 -1278
  307. package/src/renderables/EditBufferRenderable.test.ts +0 -288
  308. package/src/renderables/EditBufferRenderable.ts +0 -1152
  309. package/src/renderables/FrameBuffer.ts +0 -47
  310. package/src/renderables/Input.test.ts +0 -1310
  311. package/src/renderables/Input.ts +0 -273
  312. package/src/renderables/LineNumberRenderable.ts +0 -725
  313. package/src/renderables/Markdown.ts +0 -2144
  314. package/src/renderables/ScrollBar.ts +0 -423
  315. package/src/renderables/ScrollBox.ts +0 -903
  316. package/src/renderables/Select.test.ts +0 -1134
  317. package/src/renderables/Select.ts +0 -535
  318. package/src/renderables/Slider.test.ts +0 -456
  319. package/src/renderables/Slider.ts +0 -342
  320. package/src/renderables/TabSelect.test.ts +0 -238
  321. package/src/renderables/TabSelect.ts +0 -447
  322. package/src/renderables/Text.selection-buffer.test.ts +0 -118
  323. package/src/renderables/Text.test.ts +0 -2662
  324. package/src/renderables/Text.ts +0 -147
  325. package/src/renderables/TextBufferRenderable.ts +0 -504
  326. package/src/renderables/TextNode.test.ts +0 -1137
  327. package/src/renderables/TextNode.ts +0 -379
  328. package/src/renderables/TextTable.test.ts +0 -1411
  329. package/src/renderables/TextTable.ts +0 -1434
  330. package/src/renderables/Textarea.ts +0 -425
  331. package/src/renderables/TimeToFirstDraw.ts +0 -89
  332. package/src/renderables/__snapshots__/Code.test.ts.snap +0 -13
  333. package/src/renderables/__snapshots__/Diff.test.ts.snap +0 -785
  334. package/src/renderables/__snapshots__/Text.test.ts.snap +0 -421
  335. package/src/renderables/__snapshots__/TextTable.test.ts.snap +0 -215
  336. package/src/renderables/__tests__/Code.test.ts +0 -55
  337. package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +0 -144
  338. package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +0 -827
  339. package/src/renderables/__tests__/LineNumberRenderable.test.ts +0 -1906
  340. package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +0 -85
  341. package/src/renderables/__tests__/Markdown.code-colors.test.ts +0 -288
  342. package/src/renderables/__tests__/Markdown.test.ts +0 -4175
  343. package/src/renderables/__tests__/MultiRenderable.selection.test.ts +0 -87
  344. package/src/renderables/__tests__/Textarea.buffer.test.ts +0 -683
  345. package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +0 -675
  346. package/src/renderables/__tests__/Textarea.editing.test.ts +0 -2120
  347. package/src/renderables/__tests__/Textarea.error-handling.test.ts +0 -35
  348. package/src/renderables/__tests__/Textarea.events.test.ts +0 -738
  349. package/src/renderables/__tests__/Textarea.highlights.test.ts +0 -590
  350. package/src/renderables/__tests__/Textarea.keybinding.test.ts +0 -3275
  351. package/src/renderables/__tests__/Textarea.paste.test.ts +0 -357
  352. package/src/renderables/__tests__/Textarea.rendering.test.ts +0 -1927
  353. package/src/renderables/__tests__/Textarea.scroll.test.ts +0 -733
  354. package/src/renderables/__tests__/Textarea.selection.test.ts +0 -1589
  355. package/src/renderables/__tests__/Textarea.stress.test.ts +0 -670
  356. package/src/renderables/__tests__/Textarea.undo-redo.test.ts +0 -383
  357. package/src/renderables/__tests__/Textarea.visual-lines.test.ts +0 -310
  358. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +0 -221
  359. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +0 -89
  360. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +0 -457
  361. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +0 -158
  362. package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +0 -387
  363. package/src/renderables/__tests__/markdown-parser.test.ts +0 -241
  364. package/src/renderables/__tests__/renderable-test-utils.ts +0 -60
  365. package/src/renderables/composition/README.md +0 -8
  366. package/src/renderables/composition/VRenderable.ts +0 -32
  367. package/src/renderables/composition/constructs.ts +0 -127
  368. package/src/renderables/composition/vnode.ts +0 -277
  369. package/src/renderables/index.ts +0 -23
  370. package/src/renderables/markdown-parser.ts +0 -79
  371. package/src/renderer-theme-mode.ts +0 -199
  372. package/src/renderer.ts +0 -4975
  373. package/src/runtime-plugin-support-configure.ts +0 -63
  374. package/src/runtime-plugin-support.ts +0 -13
  375. package/src/runtime-plugin.ts +0 -626
  376. package/src/specs/terminal-startup.md +0 -64
  377. package/src/syntax-style.test.ts +0 -841
  378. package/src/syntax-style.ts +0 -274
  379. package/src/testing/README.md +0 -219
  380. package/src/testing/bun-test-node.ts +0 -880
  381. package/src/testing/capture-spans.test.ts +0 -216
  382. package/src/testing/integration.test.ts +0 -276
  383. package/src/testing/manual-clock.ts +0 -117
  384. package/src/testing/mock-keys.test.ts +0 -1378
  385. package/src/testing/mock-keys.ts +0 -457
  386. package/src/testing/mock-mouse.test.ts +0 -218
  387. package/src/testing/mock-mouse.ts +0 -247
  388. package/src/testing/mock-tree-sitter-client.ts +0 -81
  389. package/src/testing/spy.ts +0 -13
  390. package/src/testing/terminal-capabilities.ts +0 -47
  391. package/src/testing/test-recorder.test.ts +0 -410
  392. package/src/testing/test-recorder.ts +0 -133
  393. package/src/testing/test-renderer.ts +0 -375
  394. package/src/testing/test-renderer.wait.test.ts +0 -278
  395. package/src/testing/test-streams.ts +0 -31
  396. package/src/testing.ts +0 -9
  397. package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +0 -481
  398. package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +0 -19
  399. package/src/tests/__snapshots__/scrollbox.test.ts.snap +0 -29
  400. package/src/tests/absolute-positioning.snapshot.test.ts +0 -638
  401. package/src/tests/allocator-stats.test.ts +0 -53
  402. package/src/tests/audio.test.ts +0 -303
  403. package/src/tests/destroy-during-render.test.ts +0 -200
  404. package/src/tests/destroy-on-exit.fixture.ts +0 -36
  405. package/src/tests/destroy-on-exit.test.ts +0 -62
  406. package/src/tests/ffi-borrowed-pointer-callsites.test.ts +0 -153
  407. package/src/tests/hover-cursor.test.ts +0 -98
  408. package/src/tests/native-backed-measurement-lifecycle.test.ts +0 -133
  409. package/src/tests/native-backed-measurement-parity.test.ts +0 -322
  410. package/src/tests/native-span-feed-async.test.ts +0 -173
  411. package/src/tests/native-span-feed-close.test.ts +0 -120
  412. package/src/tests/native-span-feed-coverage.test.ts +0 -227
  413. package/src/tests/native-span-feed-edge-cases.test.ts +0 -384
  414. package/src/tests/native-span-feed-use-after-free.test.ts +0 -45
  415. package/src/tests/opacity.test.ts +0 -123
  416. package/src/tests/renderable.snapshot.test.ts +0 -524
  417. package/src/tests/renderable.test.ts +0 -1851
  418. package/src/tests/renderer.clock.test.ts +0 -270
  419. package/src/tests/renderer.console-startup.test.ts +0 -2151
  420. package/src/tests/renderer.control.test.ts +0 -458
  421. package/src/tests/renderer.core-slot-binding.test.ts +0 -962
  422. package/src/tests/renderer.cursor.test.ts +0 -26
  423. package/src/tests/renderer.custom-stdout.test.ts +0 -1112
  424. package/src/tests/renderer.destroy-during-render.test.ts +0 -147
  425. package/src/tests/renderer.focus-restore.test.ts +0 -257
  426. package/src/tests/renderer.focus.test.ts +0 -329
  427. package/src/tests/renderer.idle.test.ts +0 -219
  428. package/src/tests/renderer.input.test.ts +0 -2615
  429. package/src/tests/renderer.kitty-flags.test.ts +0 -195
  430. package/src/tests/renderer.lifecycle.test.ts +0 -34
  431. package/src/tests/renderer.mouse.test.ts +0 -1315
  432. package/src/tests/renderer.notifications.test.ts +0 -27
  433. package/src/tests/renderer.palette.test.ts +0 -1199
  434. package/src/tests/renderer.remote.test.ts +0 -247
  435. package/src/tests/renderer.render-stats.test.ts +0 -146
  436. package/src/tests/renderer.scrollback-surface.test.ts +0 -474
  437. package/src/tests/renderer.selection.test.ts +0 -138
  438. package/src/tests/renderer.slot-registry.test.ts +0 -684
  439. package/src/tests/renderer.tracker.test.ts +0 -202
  440. package/src/tests/renderer.useMouse.test.ts +0 -83
  441. package/src/tests/runtime-plugin-node-modules-cycle.fixture.ts +0 -76
  442. package/src/tests/runtime-plugin-node-modules-import-like-string.fixture.ts +0 -48
  443. package/src/tests/runtime-plugin-node-modules-mjs.fixture.ts +0 -43
  444. package/src/tests/runtime-plugin-node-modules-no-bare-rewrite.fixture.ts +0 -67
  445. package/src/tests/runtime-plugin-node-modules-package-type-cache.fixture.ts +0 -72
  446. package/src/tests/runtime-plugin-node-modules-runtime-specifier.fixture.ts +0 -44
  447. package/src/tests/runtime-plugin-node-modules-scoped-package-bare-rewrite.fixture.ts +0 -85
  448. package/src/tests/runtime-plugin-path-alias.fixture.ts +0 -43
  449. package/src/tests/runtime-plugin-resolve-roots.fixture.ts +0 -65
  450. package/src/tests/runtime-plugin-support-configure.fixture.ts +0 -31
  451. package/src/tests/runtime-plugin-support-late-addition.fixture.ts +0 -17
  452. package/src/tests/runtime-plugin-support.fixture.ts +0 -11
  453. package/src/tests/runtime-plugin-support.test.ts +0 -54
  454. package/src/tests/runtime-plugin-windows-file-url.fixture.ts +0 -30
  455. package/src/tests/runtime-plugin.fixture.ts +0 -40
  456. package/src/tests/runtime-plugin.test.ts +0 -369
  457. package/src/tests/scrollbox-culling-bug.test.ts +0 -114
  458. package/src/tests/scrollbox-hitgrid-resize.test.ts +0 -136
  459. package/src/tests/scrollbox-hitgrid.test.ts +0 -909
  460. package/src/tests/scrollbox.test.ts +0 -1895
  461. package/src/tests/wrap-resize-perf.test.ts +0 -276
  462. package/src/tests/yoga-api-coverage.test.ts +0 -409
  463. package/src/tests/yoga-callback-stress.test.ts +0 -122
  464. package/src/tests/yoga-ffi.test.ts +0 -117
  465. package/src/tests/yoga-setters.test.ts +0 -921
  466. package/src/tests/yoga-upstream/YGAlignBaselineTest.test.ts +0 -124
  467. package/src/tests/yoga-upstream/YGComputedBorderTest.test.ts +0 -27
  468. package/src/tests/yoga-upstream/YGComputedMarginTest.test.ts +0 -27
  469. package/src/tests/yoga-upstream/YGComputedPaddingTest.test.ts +0 -27
  470. package/src/tests/yoga-upstream/YGDirtiedTest.test.ts +0 -157
  471. package/src/tests/yoga-upstream/YGErrataTest.test.ts +0 -40
  472. package/src/tests/yoga-upstream/YGFlexBasisAuto.test.ts +0 -23
  473. package/src/tests/yoga-upstream/YGHasNewLayout.test.ts +0 -81
  474. package/src/tests/yoga-upstream/YGMeasureCacheTest.test.ts +0 -31
  475. package/src/tests/yoga-upstream/YGMeasureTest.test.ts +0 -70
  476. package/src/tests/yoga-upstream/generated/YGAbsolutePositionTest.test.ts +0 -1864
  477. package/src/tests/yoga-upstream/generated/YGAlignContentTest.test.ts +0 -5829
  478. package/src/tests/yoga-upstream/generated/YGAlignItemsTest.test.ts +0 -2444
  479. package/src/tests/yoga-upstream/generated/YGAlignSelfTest.test.ts +0 -293
  480. package/src/tests/yoga-upstream/generated/YGAndroidNewsFeed.test.ts +0 -315
  481. package/src/tests/yoga-upstream/generated/YGAspectRatioTest.test.ts +0 -231
  482. package/src/tests/yoga-upstream/generated/YGAutoTest.test.ts +0 -347
  483. package/src/tests/yoga-upstream/generated/YGBorderTest.test.ts +0 -256
  484. package/src/tests/yoga-upstream/generated/YGBoxSizingTest.test.ts +0 -2747
  485. package/src/tests/yoga-upstream/generated/YGDimensionTest.test.ts +0 -129
  486. package/src/tests/yoga-upstream/generated/YGDisplayContentsTest.test.ts +0 -109
  487. package/src/tests/yoga-upstream/generated/YGDisplayTest.test.ts +0 -1097
  488. package/src/tests/yoga-upstream/generated/YGFlexDirectionTest.test.ts +0 -4562
  489. package/src/tests/yoga-upstream/generated/YGFlexTest.test.ts +0 -677
  490. package/src/tests/yoga-upstream/generated/YGFlexWrapTest.test.ts +0 -2071
  491. package/src/tests/yoga-upstream/generated/YGGapTest.test.ts +0 -3303
  492. package/src/tests/yoga-upstream/generated/YGIntrinsicSizeTest.test.ts +0 -582
  493. package/src/tests/yoga-upstream/generated/YGJustifyContentTest.test.ts +0 -2150
  494. package/src/tests/yoga-upstream/generated/YGMarginTest.test.ts +0 -1963
  495. package/src/tests/yoga-upstream/generated/YGMinMaxDimensionTest.test.ts +0 -1446
  496. package/src/tests/yoga-upstream/generated/YGPaddingTest.test.ts +0 -354
  497. package/src/tests/yoga-upstream/generated/YGPercentageTest.test.ts +0 -1760
  498. package/src/tests/yoga-upstream/generated/YGRoundingTest.test.ts +0 -1161
  499. package/src/tests/yoga-upstream/generated/YGSizeOverflowTest.test.ts +0 -207
  500. package/src/tests/yoga-upstream/generated/YGStaticPositionTest.test.ts +0 -6338
  501. package/src/tests/yoga-upstream/tools/MeasureCounter.ts +0 -54
  502. package/src/tests/yoga-upstream/tools/utils.ts +0 -81
  503. package/src/text-buffer-view.test.ts +0 -722
  504. package/src/text-buffer-view.ts +0 -193
  505. package/src/text-buffer.test.ts +0 -512
  506. package/src/text-buffer.ts +0 -250
  507. package/src/types.ts +0 -199
  508. package/src/utils.ts +0 -88
  509. package/src/yoga.ts +0 -1146
  510. package/src/zig/ansi.zig +0 -502
  511. package/src/zig/audio.zig +0 -1206
  512. package/src/zig/bench/README.md +0 -50
  513. package/src/zig/bench/buffer-color-blending_bench.zig +0 -350
  514. package/src/zig/bench/buffer-draw-box_bench.zig +0 -786
  515. package/src/zig/bench/buffer-draw-text-buffer_bench.zig +0 -894
  516. package/src/zig/bench/edit-buffer_bench.zig +0 -476
  517. package/src/zig/bench/editor-view_bench.zig +0 -169
  518. package/src/zig/bench/native-span-feed_bench.zig +0 -107
  519. package/src/zig/bench/rope-markers_bench.zig +0 -713
  520. package/src/zig/bench/rope_bench.zig +0 -514
  521. package/src/zig/bench/styled-text_bench.zig +0 -476
  522. package/src/zig/bench/text-buffer-coords_bench.zig +0 -362
  523. package/src/zig/bench/text-buffer-view_bench.zig +0 -459
  524. package/src/zig/bench/text-chunk-graphemes_bench.zig +0 -272
  525. package/src/zig/bench/utf8_bench.zig +0 -799
  526. package/src/zig/bench-utils.zig +0 -431
  527. package/src/zig/bench.zig +0 -223
  528. package/src/zig/buffer-methods.zig +0 -215
  529. package/src/zig/buffer.zig +0 -2515
  530. package/src/zig/build.zig +0 -700
  531. package/src/zig/build.zig.zon +0 -19
  532. package/src/zig/edit-buffer.zig +0 -900
  533. package/src/zig/editor-view.zig +0 -812
  534. package/src/zig/event-bus.zig +0 -28
  535. package/src/zig/event-emitter.zig +0 -65
  536. package/src/zig/file-logger.zig +0 -92
  537. package/src/zig/grapheme.zig +0 -838
  538. package/src/zig/handles.zig +0 -267
  539. package/src/zig/lib.zig +0 -2813
  540. package/src/zig/link.zig +0 -349
  541. package/src/zig/logger.zig +0 -43
  542. package/src/zig/mem-registry.zig +0 -126
  543. package/src/zig/miniaudio_shim.c +0 -21
  544. package/src/zig/native-renderable.zig +0 -112
  545. package/src/zig/native-span-feed-bench-lib.zig +0 -7
  546. package/src/zig/native-span-feed.zig +0 -747
  547. package/src/zig/renderer-output.zig +0 -677
  548. package/src/zig/renderer.zig +0 -2106
  549. package/src/zig/rope.zig +0 -1220
  550. package/src/zig/split-scrollback.zig +0 -88
  551. package/src/zig/syntax-style.zig +0 -174
  552. package/src/zig/terminal.zig +0 -1652
  553. package/src/zig/test.zig +0 -82
  554. package/src/zig/tests/README.md +0 -18
  555. package/src/zig/tests/ansi_test.zig +0 -18
  556. package/src/zig/tests/audio_test.zig +0 -439
  557. package/src/zig/tests/buffer-methods_test.zig +0 -1111
  558. package/src/zig/tests/buffer_test.zig +0 -2926
  559. package/src/zig/tests/edit-buffer-history_test.zig +0 -299
  560. package/src/zig/tests/edit-buffer_test.zig +0 -1688
  561. package/src/zig/tests/editor-view_test.zig +0 -3454
  562. package/src/zig/tests/event-emitter_test.zig +0 -249
  563. package/src/zig/tests/grapheme_test.zig +0 -1329
  564. package/src/zig/tests/handles_test.zig +0 -123
  565. package/src/zig/tests/link_test.zig +0 -220
  566. package/src/zig/tests/mem-registry_test.zig +0 -473
  567. package/src/zig/tests/memory_leak_regression_test.zig +0 -234
  568. package/src/zig/tests/native-renderable_test.zig +0 -16
  569. package/src/zig/tests/native-span-feed_test.zig +0 -1266
  570. package/src/zig/tests/renderer_test.zig +0 -2604
  571. package/src/zig/tests/rope-nested_test.zig +0 -712
  572. package/src/zig/tests/rope_fuzz_test.zig +0 -238
  573. package/src/zig/tests/rope_test.zig +0 -2362
  574. package/src/zig/tests/segment-merge.test.zig +0 -148
  575. package/src/zig/tests/split-scrollback_test.zig +0 -70
  576. package/src/zig/tests/syntax-style_test.zig +0 -558
  577. package/src/zig/tests/terminal_test.zig +0 -1489
  578. package/src/zig/tests/test-renderer.zig +0 -126
  579. package/src/zig/tests/text-buffer-drawing_test.zig +0 -3291
  580. package/src/zig/tests/text-buffer-highlights_test.zig +0 -706
  581. package/src/zig/tests/text-buffer-iterators_test.zig +0 -776
  582. package/src/zig/tests/text-buffer-segment_test.zig +0 -320
  583. package/src/zig/tests/text-buffer-selection_test.zig +0 -1056
  584. package/src/zig/tests/text-buffer-selection_viewport_test.zig +0 -358
  585. package/src/zig/tests/text-buffer-view_test.zig +0 -3672
  586. package/src/zig/tests/text-buffer_test.zig +0 -2191
  587. package/src/zig/tests/unicode-width-map.zon +0 -3909
  588. package/src/zig/tests/utf8_no_zwj_test.zig +0 -260
  589. package/src/zig/tests/utf8_test.zig +0 -4060
  590. package/src/zig/tests/utf8_wcwidth_cursor_test.zig +0 -267
  591. package/src/zig/tests/utf8_wcwidth_test.zig +0 -357
  592. package/src/zig/tests/word-wrap-editing_test.zig +0 -498
  593. package/src/zig/tests/wrap-cache-perf_test.zig +0 -113
  594. package/src/zig/tests/yoga_test.zig +0 -65
  595. package/src/zig/text-buffer-iterators.zig +0 -496
  596. package/src/zig/text-buffer-segment.zig +0 -403
  597. package/src/zig/text-buffer-view.zig +0 -1428
  598. package/src/zig/text-buffer.zig +0 -1272
  599. package/src/zig/utf8.zig +0 -1954
  600. package/src/zig/utils.zig +0 -12
  601. package/src/zig/uucode-stub.zig +0 -76
  602. package/src/zig/vendor/miniaudio/miniaudio.h +0 -93468
  603. package/src/zig/yoga.zig +0 -658
  604. package/src/zig-structs.ts +0 -381
  605. package/src/zig.ts +0 -5260
  606. package/tsconfig.build.json +0 -17
  607. package/tsconfig.json +0 -27
  608. package/tsconfig.node-test.json +0 -138
  609. /package/{src/lib/tree-sitter/assets → assets}/javascript/highlights.scm +0 -0
  610. /package/{src/lib/tree-sitter/assets → assets}/javascript/tree-sitter-javascript.wasm +0 -0
  611. /package/{src/lib/tree-sitter/assets → assets}/markdown/highlights.scm +0 -0
  612. /package/{src/lib/tree-sitter/assets → assets}/markdown/injections.scm +0 -0
  613. /package/{src/lib/tree-sitter/assets → assets}/markdown/tree-sitter-markdown.wasm +0 -0
  614. /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/highlights.scm +0 -0
  615. /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
  616. /package/{src/lib/tree-sitter/assets → assets}/typescript/highlights.scm +0 -0
  617. /package/{src/lib/tree-sitter/assets → assets}/typescript/tree-sitter-typescript.wasm +0 -0
  618. /package/{src/lib/tree-sitter/assets → assets}/zig/highlights.scm +0 -0
  619. /package/{src/lib/tree-sitter/assets → assets}/zig/tree-sitter-zig.wasm +0 -0
@@ -1,1796 +0,0 @@
1
- #!/usr/bin/env bun
2
-
3
- import { MarkdownRenderable, SyntaxStyle, createCliRenderer, parseColor } from "../index.js"
4
- import { resolveRenderLib } from "../zig.js"
5
- import { Command } from "commander"
6
- import path from "node:path"
7
- import { existsSync } from "node:fs"
8
- import { mkdir, mkdtemp, readFile, unlink } from "node:fs/promises"
9
- import { tmpdir } from "node:os"
10
-
11
- const realStdoutWrite = process.stdout.write.bind(process.stdout)
12
- const nativeLib = resolveRenderLib()
13
- const nativeBuildOptions = nativeLib.getBuildOptions()
14
-
15
- const WORDS = [
16
- "alpha",
17
- "bravo",
18
- "charlie",
19
- "delta",
20
- "echo",
21
- "foxtrot",
22
- "golf",
23
- "hotel",
24
- "india",
25
- "juliet",
26
- "kilo",
27
- "lima",
28
- "mango",
29
- "nectar",
30
- "oscar",
31
- "papa",
32
- "quartz",
33
- "romeo",
34
- "sierra",
35
- "tango",
36
- "uniform",
37
- "vector",
38
- "whiskey",
39
- "xray",
40
- "yankee",
41
- "zulu",
42
- "matrix",
43
- "signal",
44
- "tensor",
45
- "render",
46
- "schema",
47
- "buffer",
48
- "layout",
49
- "stream",
50
- "parser",
51
- "syntax",
52
- "viewport",
53
- "cursor",
54
- ]
55
-
56
- const CODE_WORDS = [
57
- "buffer",
58
- "column",
59
- "row",
60
- "token",
61
- "state",
62
- "table",
63
- "stream",
64
- "render",
65
- "result",
66
- "index",
67
- "value",
68
- "output",
69
- "content",
70
- ]
71
-
72
- type MemorySample = {
73
- rss: number
74
- heapTotal: number
75
- heapUsed: number
76
- external: number
77
- arrayBuffers: number
78
- }
79
-
80
- type MemoryFieldStats = {
81
- min: number
82
- max: number
83
- avg: number
84
- median: number
85
- }
86
-
87
- type MemoryStats = {
88
- samples: number
89
- start: MemorySample
90
- end: MemorySample
91
- delta: MemorySample
92
- peak: MemorySample
93
- fields: {
94
- rss: MemoryFieldStats
95
- heapTotal: MemoryFieldStats
96
- heapUsed: MemoryFieldStats
97
- external: MemoryFieldStats
98
- arrayBuffers: MemoryFieldStats
99
- }
100
- }
101
-
102
- type NativeMemorySample = {
103
- totalRequestedBytes: number
104
- activeAllocations: number
105
- smallAllocations: number
106
- largeAllocations: number
107
- requestedBytesValid: boolean
108
- }
109
-
110
- type NativeMemoryStats = {
111
- samples: number
112
- start: NativeMemorySample
113
- end: NativeMemorySample
114
- delta: NativeMemorySample
115
- peak: NativeMemorySample
116
- requestedBytesReliable: boolean
117
- fields: {
118
- totalRequestedBytes: MemoryFieldStats
119
- activeAllocations: MemoryFieldStats
120
- smallAllocations: MemoryFieldStats
121
- largeAllocations: MemoryFieldStats
122
- }
123
- }
124
-
125
- type TimingStats = {
126
- count: number
127
- averageMs: number
128
- medianMs: number
129
- p95Ms: number
130
- minMs: number
131
- maxMs: number
132
- stdDevMs: number
133
- }
134
-
135
- type ScenarioResult = {
136
- name: string
137
- description: string
138
- iterations: number
139
- warmupIterations: number
140
- elapsedMs: number
141
- category: "parse" | "incremental" | "style"
142
- timingMode: "content-set" | "style-refresh"
143
- updateStats: TimingStats
144
- memoryStats?: MemoryStats
145
- nativeMemoryStats?: NativeMemoryStats
146
- contentStats: {
147
- initialChars: number
148
- finalChars: number
149
- maxChars: number
150
- updates: number
151
- appendedChars: number
152
- }
153
- settings: Record<string, unknown>
154
- }
155
-
156
- type StaticScenarioPlan = {
157
- kind: "static"
158
- name: string
159
- description: string
160
- iterations: number
161
- warmupIterations: number
162
- content: string
163
- contentStats: Record<string, number>
164
- }
165
-
166
- type StreamingScenarioPlan = {
167
- kind: "streaming"
168
- name: string
169
- description: string
170
- iterations: number
171
- warmupIterations: number
172
- baseContent: string
173
- chunks: string[]
174
- repeat: boolean
175
- contentStats: Record<string, number>
176
- }
177
-
178
- type StyleScenarioPlan = {
179
- kind: "style"
180
- name: string
181
- description: string
182
- iterations: number
183
- warmupIterations: number
184
- content: string
185
- contentStats: Record<string, number>
186
- }
187
-
188
- type ScenarioPlan = StaticScenarioPlan | StreamingScenarioPlan | StyleScenarioPlan
189
-
190
- type StreamState = {
191
- content: string
192
- chunks: string[]
193
- cursor: number
194
- repeat: boolean
195
- maxChars: number
196
- maxContentChars: number
197
- done: boolean
198
- }
199
-
200
- type RunContext = {
201
- renderer: Awaited<ReturnType<typeof createCliRenderer>>
202
- markdown: MarkdownRenderable
203
- syntaxStyleA: SyntaxStyle
204
- syntaxStyleB: SyntaxStyle
205
- streamIntervalMs: number
206
- chunkLines: number
207
- maxChars: number
208
- memInterval: number
209
- memSampleEvery: number
210
- }
211
-
212
- type SuiteConfig = {
213
- iterations: number
214
- warmupIterations: number
215
- longIterations: number
216
- scale: number
217
- }
218
-
219
- type MemorySampler = {
220
- jsSamples: MemorySample[]
221
- nativeSamples: NativeMemorySample[]
222
- recordIteration: (iteration: number) => void
223
- stop: () => void
224
- }
225
-
226
- type StaticScenarioConfig = {
227
- title: string
228
- sections: number
229
- paragraphsPerSection: number
230
- sentencesPerParagraph: number
231
- lists: number
232
- listItems: number
233
- tables: number
234
- tableRows: number
235
- tableCols: number
236
- codeBlocks: number
237
- codeLines: number
238
- }
239
-
240
- type StreamingScenarioConfig = StaticScenarioConfig & {
241
- repeat: boolean
242
- }
243
-
244
- type OutputMeta = {
245
- suiteName: string
246
- targetFps: number
247
- maxFps: number
248
- iterations: number
249
- warmupIterations: number
250
- longIterations: number
251
- streamIntervalMs: number
252
- chunkLines: number
253
- maxChars: number
254
- scale: number
255
- seed: number
256
- memInterval: number
257
- memSampleEvery: number
258
- gpaSafeStats: boolean
259
- gpaMemoryLimitTracking: boolean
260
- }
261
-
262
- const program = new Command()
263
- program
264
- .name("markdown-benchmark")
265
- .description("MarkdownRenderable benchmark scenarios (frame-independent)")
266
- .option("-s, --suite <name>", "benchmark suite: quick, default, long", "default")
267
- .option("-i, --iterations <count>", "iterations per scenario", "1000")
268
- .option("--warmup-iterations <count>", "warmup iterations per scenario", "50")
269
- .option("--long-iterations <count>", "iterations for long streaming scenario", "3000")
270
- .option("--target-fps <fps>", "renderer target fps", "60")
271
- .option("--max-fps <fps>", "renderer max fps", "60")
272
- .option("--mem-interval <ms>", "time-based memory sampling in ms (0 disables)", "0")
273
- .option("--mem-sample-every <count>", "sample memory every N iterations (0 disables)", "10")
274
- .option("--stream-interval <ms>", "stream update interval in ms", "0")
275
- .option("--chunk-lines <count>", "lines appended per stream tick", "4")
276
- .option("--max-chars <count>", "max streaming content size before stopping growth", "5000000")
277
- .option("--scale <n>", "scale content size", "1")
278
- .option("--seed <n>", "seed for deterministic content", "1337")
279
- .option("--json [path]", "write JSON results to file")
280
- .option("--no-testing", "use production renderer (outputs to terminal)")
281
- .option("--scenario <name>", "run a single scenario")
282
- .option("--no-spawn-per-scenario", "run all scenarios in a single process")
283
- .option("--no-output", "suppress stdout output")
284
- .parse(process.argv)
285
-
286
- const options = program.opts()
287
-
288
- const suiteName = String(options.suite)
289
- const iterations = Math.max(1, Math.floor(toNumber(options.iterations, 1000)))
290
- const warmupIterations = Math.max(0, Math.floor(toNumber(options.warmupIterations, 50)))
291
- const longIterations = Math.max(iterations, Math.floor(toNumber(options.longIterations, 3000)))
292
- const targetFps = toNumber(options.targetFps, 60)
293
- const maxFps = toNumber(options.maxFps, 60)
294
- const memInterval = Math.max(0, Math.floor(toNumber(options.memInterval, 0)))
295
- const memSampleEvery = Math.max(0, Math.floor(toNumber(options.memSampleEvery, 10)))
296
- const streamIntervalMs = Math.max(0, Math.floor(toNumber(options.streamInterval, 0)))
297
- const chunkLines = Math.max(1, Math.floor(toNumber(options.chunkLines, 4)))
298
- const maxChars = Math.max(0, Math.floor(toNumber(options.maxChars, 5000000)))
299
- const scale = Math.max(0.25, toNumber(options.scale, 1))
300
- const seed = Math.max(1, Math.floor(toNumber(options.seed, 1337)))
301
- const testing = options.testing !== false
302
- const outputEnabled = options.output !== false
303
- const scenarioFilter = options.scenario ? String(options.scenario) : null
304
- const spawnPerScenario = options.spawnPerScenario !== false
305
-
306
- const jsonArg = options.json
307
- const jsonPath =
308
- typeof jsonArg === "string"
309
- ? path.resolve(process.cwd(), jsonArg)
310
- : jsonArg
311
- ? path.resolve(process.cwd(), "latest-markdown-bench-run.json")
312
- : null
313
-
314
- if (jsonPath) {
315
- const dir = path.dirname(jsonPath)
316
- if (!existsSync(dir)) {
317
- await mkdir(dir, { recursive: true })
318
- }
319
- if (existsSync(jsonPath)) {
320
- console.error(`Error: output file already exists: ${jsonPath}`)
321
- process.exit(1)
322
- }
323
- }
324
-
325
- const scenarios = createScenarios(
326
- suiteName,
327
- {
328
- iterations,
329
- warmupIterations,
330
- longIterations,
331
- scale,
332
- },
333
- seed,
334
- )
335
-
336
- const filteredScenarios = scenarioFilter ? scenarios.filter((scenario) => scenario.name === scenarioFilter) : scenarios
337
-
338
- if (scenarioFilter && filteredScenarios.length === 0) {
339
- writeLine(`Unknown scenario: ${scenarioFilter}`)
340
- process.exit(1)
341
- }
342
-
343
- if (filteredScenarios.length === 0) {
344
- console.error(`Unknown suite: ${suiteName}`)
345
- process.exit(1)
346
- }
347
-
348
- if (spawnPerScenario && !scenarioFilter) {
349
- await runSpawnedScenarios(filteredScenarios)
350
- process.exit(0)
351
- }
352
-
353
- const renderer = await createCliRenderer({
354
- exitOnCtrlC: true,
355
- targetFps,
356
- maxFps,
357
- testing,
358
- screenMode: "main-screen",
359
- externalOutputMode: "passthrough",
360
- consoleMode: "disabled",
361
- useMouse: false,
362
- })
363
-
364
- renderer.requestRender = () => {}
365
-
366
- const syntaxStyleA = SyntaxStyle.fromStyles({
367
- default: { fg: parseColor("#E6EDF3") },
368
- "markup.heading": { fg: parseColor("#88C0D0"), bold: true },
369
- "markup.heading.1": { fg: parseColor("#8FBCBB"), bold: true },
370
- "markup.heading.2": { fg: parseColor("#81A1C1"), bold: true },
371
- "markup.heading.3": { fg: parseColor("#5E81AC"), bold: true },
372
- "markup.bold": { fg: parseColor("#ECEFF4"), bold: true },
373
- "markup.strong": { fg: parseColor("#ECEFF4"), bold: true },
374
- "markup.italic": { fg: parseColor("#E5E9F0"), italic: true },
375
- "markup.list": { fg: parseColor("#B48EAD") },
376
- "markup.raw": { fg: parseColor("#A3BE8C") },
377
- "markup.raw.block": { fg: parseColor("#A3BE8C") },
378
- "markup.raw.inline": { fg: parseColor("#A3BE8C") },
379
- "markup.link": { fg: parseColor("#81A1C1"), underline: true },
380
- "markup.link.label": { fg: parseColor("#88C0D0"), underline: true },
381
- "markup.link.url": { fg: parseColor("#88C0D0"), underline: true },
382
- "punctuation.special": { fg: parseColor("#616E88") },
383
- conceal: { fg: parseColor("#4C566A") },
384
- })
385
-
386
- const syntaxStyleB = SyntaxStyle.fromStyles({
387
- default: { fg: parseColor("#F8F8F2") },
388
- "markup.heading": { fg: parseColor("#A6E22E"), bold: true },
389
- "markup.heading.1": { fg: parseColor("#F92672"), bold: true },
390
- "markup.heading.2": { fg: parseColor("#66D9EF"), bold: true },
391
- "markup.heading.3": { fg: parseColor("#E6DB74") },
392
- "markup.bold": { fg: parseColor("#F8F8F2"), bold: true },
393
- "markup.strong": { fg: parseColor("#F8F8F2"), bold: true },
394
- "markup.italic": { fg: parseColor("#F8F8F2"), italic: true },
395
- "markup.list": { fg: parseColor("#F92672") },
396
- "markup.raw": { fg: parseColor("#E6DB74") },
397
- "markup.raw.block": { fg: parseColor("#E6DB74") },
398
- "markup.raw.inline": { fg: parseColor("#E6DB74") },
399
- "markup.link": { fg: parseColor("#66D9EF"), underline: true },
400
- "markup.link.label": { fg: parseColor("#E6DB74"), underline: true },
401
- "markup.link.url": { fg: parseColor("#66D9EF"), underline: true },
402
- "punctuation.special": { fg: parseColor("#75715E") },
403
- conceal: { fg: parseColor("#75715E") },
404
- })
405
-
406
- const markdown = new MarkdownRenderable(renderer, {
407
- id: "markdown-bench",
408
- content: "",
409
- syntaxStyle: syntaxStyleA,
410
- conceal: true,
411
- })
412
-
413
- const ctx: RunContext = {
414
- renderer,
415
- markdown,
416
- syntaxStyleA,
417
- syntaxStyleB,
418
- streamIntervalMs,
419
- chunkLines,
420
- maxChars,
421
- memInterval,
422
- memSampleEvery,
423
- }
424
-
425
- const results: ScenarioResult[] = []
426
- const scenarioLines: string[] = []
427
-
428
- try {
429
- for (let i = 0; i < filteredScenarios.length; i += 1) {
430
- const plan = filteredScenarios[i]
431
- const result = await runScenario(plan, ctx)
432
- scenarioLines.push(formatScenarioResult(result))
433
- results.push(result)
434
- }
435
- } finally {
436
- renderer.destroy()
437
- }
438
-
439
- await outputResults(
440
- {
441
- suiteName,
442
- targetFps,
443
- maxFps,
444
- iterations,
445
- warmupIterations,
446
- longIterations,
447
- streamIntervalMs,
448
- chunkLines,
449
- maxChars,
450
- scale,
451
- seed,
452
- memInterval,
453
- memSampleEvery,
454
- gpaSafeStats: nativeBuildOptions.gpaSafeStats,
455
- gpaMemoryLimitTracking: nativeBuildOptions.gpaMemoryLimitTracking,
456
- },
457
- results,
458
- scenarioLines,
459
- outputEnabled,
460
- jsonPath,
461
- )
462
-
463
- function createScenarios(suite: string, config: SuiteConfig, runSeed: number): ScenarioPlan[] {
464
- const rng = createRng(runSeed)
465
- const baseIterations = config.iterations
466
- const baseWarmup = config.warmupIterations
467
- const longIterations = config.longIterations
468
-
469
- const staticSmallDoc = buildMarkdownDocument(rng, {
470
- title: "Markdown Static Small",
471
- sections: scaled(3, config.scale),
472
- paragraphsPerSection: scaled(2, config.scale),
473
- sentencesPerParagraph: 3,
474
- lists: scaled(2, config.scale),
475
- listItems: 6,
476
- tables: scaled(2, config.scale),
477
- tableRows: scaled(12, config.scale),
478
- tableCols: 4,
479
- codeBlocks: scaled(2, config.scale),
480
- codeLines: 8,
481
- })
482
-
483
- const staticLargeDoc = buildMarkdownDocument(rng, {
484
- title: "Markdown Static Large",
485
- sections: scaled(6, config.scale),
486
- paragraphsPerSection: scaled(3, config.scale),
487
- sentencesPerParagraph: 4,
488
- lists: scaled(3, config.scale),
489
- listItems: 8,
490
- tables: scaled(6, config.scale),
491
- tableRows: scaled(40, config.scale),
492
- tableCols: 6,
493
- codeBlocks: scaled(4, config.scale),
494
- codeLines: 14,
495
- })
496
-
497
- const tableOnlySmallDoc = buildTableOnlyDocument(rng, {
498
- title: "Markdown Tables Only Small",
499
- tables: scaled(3, config.scale),
500
- rows: scaled(24, config.scale),
501
- cols: 4,
502
- })
503
-
504
- const tableOnlyLargeDoc = buildTableOnlyDocument(rng, {
505
- title: "Markdown Tables Only Large",
506
- tables: scaled(8, config.scale),
507
- rows: scaled(60, config.scale),
508
- cols: 6,
509
- })
510
-
511
- const codeOnlySmallDoc = buildCodeOnlyDocument(rng, {
512
- title: "Markdown Code Only Small",
513
- blocks: scaled(8, config.scale),
514
- lines: scaled(10, config.scale),
515
- })
516
-
517
- const codeOnlyLargeDoc = buildCodeOnlyDocument(rng, {
518
- title: "Markdown Code Only Large",
519
- blocks: scaled(24, config.scale),
520
- lines: scaled(16, config.scale),
521
- })
522
-
523
- const headingsOnlyDoc = buildHeadingsOnlyDocument(rng, {
524
- title: "Markdown Headings Only",
525
- headings: scaled(200, config.scale),
526
- depthMin: 2,
527
- depthMax: 4,
528
- wordsPerHeading: 4,
529
- })
530
-
531
- const streamMixedConfig = {
532
- title: "Markdown Stream Mixed",
533
- sections: scaled(5, config.scale),
534
- paragraphsPerSection: scaled(2, config.scale),
535
- sentencesPerParagraph: 3,
536
- lists: scaled(2, config.scale),
537
- listItems: 6,
538
- tables: scaled(4, config.scale),
539
- tableRows: scaled(18, config.scale),
540
- tableCols: 5,
541
- codeBlocks: scaled(3, config.scale),
542
- codeLines: 10,
543
- repeat: true,
544
- }
545
-
546
- const streamTablesConfig = {
547
- title: "Markdown Stream Tables Long",
548
- sections: scaled(4, config.scale),
549
- paragraphsPerSection: scaled(1, config.scale),
550
- sentencesPerParagraph: 2,
551
- lists: scaled(1, config.scale),
552
- listItems: 4,
553
- tables: scaled(8, config.scale),
554
- tableRows: scaled(50, config.scale),
555
- tableCols: 6,
556
- codeBlocks: scaled(2, config.scale),
557
- codeLines: 8,
558
- repeat: true,
559
- }
560
-
561
- const streamMixedBase = buildMarkdownDocument(rng, {
562
- ...streamMixedConfig,
563
- tables: Math.max(1, Math.floor(streamMixedConfig.tables / 2)),
564
- tableRows: Math.max(6, Math.floor(streamMixedConfig.tableRows / 2)),
565
- codeBlocks: Math.max(1, Math.floor(streamMixedConfig.codeBlocks / 2)),
566
- })
567
-
568
- const streamTablesBase = buildMarkdownDocument(rng, {
569
- ...streamTablesConfig,
570
- tables: Math.max(1, Math.floor(streamTablesConfig.tables / 2)),
571
- tableRows: Math.max(6, Math.floor(streamTablesConfig.tableRows / 2)),
572
- codeBlocks: Math.max(1, Math.floor(streamTablesConfig.codeBlocks / 2)),
573
- })
574
-
575
- const streamMixedChunks = buildStreamingChunks(rng, streamMixedConfig)
576
- const streamTablesChunks = buildStreamingChunks(rng, streamTablesConfig)
577
-
578
- const tableRowStreamCols = Math.max(3, scaled(6, config.scale))
579
- const tableRowStreamBaseRows = 1
580
- const tableRowStreamRows = Math.max(200, scaled(400, config.scale))
581
- const tableRowStreamBaseLines = makeTableLines(rng, tableRowStreamCols, tableRowStreamBaseRows)
582
- const tableRowStreamBaseContent = `# Stream Table Rows\n\n${tableRowStreamBaseLines.join("\n")}\n`
583
- const tableRowStreamChunks = buildTableRowChunks(rng, {
584
- rows: tableRowStreamRows,
585
- cols: tableRowStreamCols,
586
- })
587
-
588
- const codeBlockStreamBlocks = Math.max(40, scaled(80, config.scale))
589
- const codeBlockStreamLines = Math.max(6, scaled(10, config.scale))
590
- const codeBlockStreamBaseContent = "# Stream Code Blocks\n\n"
591
- const codeBlockStreamChunks = buildCodeBlockChunks(rng, {
592
- blocks: codeBlockStreamBlocks,
593
- lines: codeBlockStreamLines,
594
- })
595
-
596
- const headingStreamCount = Math.max(200, scaled(400, config.scale))
597
- const headingStreamBaseContent = "# Stream Headings\n\n"
598
- const headingStreamChunks = buildHeadingChunks(rng, {
599
- headings: headingStreamCount,
600
- depthMin: 2,
601
- depthMax: 4,
602
- wordsPerHeading: 4,
603
- })
604
-
605
- const staticSmall: StaticScenarioPlan = {
606
- kind: "static",
607
- name: "parse_small",
608
- description: "Full parse/build on a small static document",
609
- iterations: baseIterations,
610
- warmupIterations: baseWarmup,
611
- content: staticSmallDoc.content,
612
- contentStats: staticSmallDoc.stats,
613
- }
614
-
615
- const staticLarge: StaticScenarioPlan = {
616
- kind: "static",
617
- name: "parse_large_tables",
618
- description: "Full parse/build on a large, table-heavy document",
619
- iterations: baseIterations,
620
- warmupIterations: baseWarmup,
621
- content: staticLargeDoc.content,
622
- contentStats: staticLargeDoc.stats,
623
- }
624
-
625
- const tableOnlySmall: StaticScenarioPlan = {
626
- kind: "static",
627
- name: "parse_tables_only_small",
628
- description: "Full parse/build on tables-only small document",
629
- iterations: baseIterations,
630
- warmupIterations: baseWarmup,
631
- content: tableOnlySmallDoc.content,
632
- contentStats: tableOnlySmallDoc.stats,
633
- }
634
-
635
- const tableOnlyLarge: StaticScenarioPlan = {
636
- kind: "static",
637
- name: "parse_tables_only_large",
638
- description: "Full parse/build on tables-only large document",
639
- iterations: baseIterations,
640
- warmupIterations: baseWarmup,
641
- content: tableOnlyLargeDoc.content,
642
- contentStats: tableOnlyLargeDoc.stats,
643
- }
644
-
645
- const codeOnlySmall: StaticScenarioPlan = {
646
- kind: "static",
647
- name: "parse_code_only_small",
648
- description: "Full parse/build on code-only document",
649
- iterations: baseIterations,
650
- warmupIterations: baseWarmup,
651
- content: codeOnlySmallDoc.content,
652
- contentStats: codeOnlySmallDoc.stats,
653
- }
654
-
655
- const codeOnlyLarge: StaticScenarioPlan = {
656
- kind: "static",
657
- name: "parse_code_only_large",
658
- description: "Full parse/build on large code-only document",
659
- iterations: baseIterations,
660
- warmupIterations: baseWarmup,
661
- content: codeOnlyLargeDoc.content,
662
- contentStats: codeOnlyLargeDoc.stats,
663
- }
664
-
665
- const headingsOnly: StaticScenarioPlan = {
666
- kind: "static",
667
- name: "parse_headings_only",
668
- description: "Full parse/build on headings-only document",
669
- iterations: baseIterations,
670
- warmupIterations: baseWarmup,
671
- content: headingsOnlyDoc.content,
672
- contentStats: headingsOnlyDoc.stats,
673
- }
674
-
675
- const streamMixed: StreamingScenarioPlan = {
676
- kind: "streaming",
677
- name: "incremental_mixed",
678
- description: "Incremental parsing with mixed streamed content",
679
- iterations: baseIterations,
680
- warmupIterations: baseWarmup,
681
- baseContent: streamMixedBase.content,
682
- chunks: streamMixedChunks,
683
- repeat: true,
684
- contentStats: {
685
- ...streamMixedBase.stats,
686
- streamTables: streamMixedConfig.tables,
687
- streamTableRows: streamMixedConfig.tableRows,
688
- streamTableCols: streamMixedConfig.tableCols,
689
- streamLists: streamMixedConfig.lists,
690
- streamListItems: streamMixedConfig.listItems,
691
- streamCodeBlocks: streamMixedConfig.codeBlocks,
692
- streamCodeLines: streamMixedConfig.codeLines,
693
- },
694
- }
695
-
696
- const streamTablesLong: StreamingScenarioPlan = {
697
- kind: "streaming",
698
- name: "incremental_tables_long",
699
- description: "Long incremental run with large tables",
700
- iterations: longIterations,
701
- warmupIterations: baseWarmup,
702
- baseContent: streamTablesBase.content,
703
- chunks: streamTablesChunks,
704
- repeat: true,
705
- contentStats: {
706
- ...streamTablesBase.stats,
707
- streamTables: streamTablesConfig.tables,
708
- streamTableRows: streamTablesConfig.tableRows,
709
- streamTableCols: streamTablesConfig.tableCols,
710
- streamLists: streamTablesConfig.lists,
711
- streamListItems: streamTablesConfig.listItems,
712
- streamCodeBlocks: streamTablesConfig.codeBlocks,
713
- streamCodeLines: streamTablesConfig.codeLines,
714
- },
715
- }
716
-
717
- const streamTableRows: StreamingScenarioPlan = {
718
- kind: "streaming",
719
- name: "incremental_table_rows",
720
- description: "Incremental parsing on growing single table rows",
721
- iterations: baseIterations,
722
- warmupIterations: baseWarmup,
723
- baseContent: tableRowStreamBaseContent,
724
- chunks: tableRowStreamChunks,
725
- repeat: true,
726
- contentStats: {
727
- tableCols: tableRowStreamCols,
728
- baseRows: tableRowStreamBaseRows,
729
- streamRows: tableRowStreamRows,
730
- },
731
- }
732
-
733
- const streamCodeBlocks: StreamingScenarioPlan = {
734
- kind: "streaming",
735
- name: "incremental_code_blocks",
736
- description: "Incremental parsing with appended code blocks",
737
- iterations: baseIterations,
738
- warmupIterations: baseWarmup,
739
- baseContent: codeBlockStreamBaseContent,
740
- chunks: codeBlockStreamChunks,
741
- repeat: true,
742
- contentStats: {
743
- codeBlocks: codeBlockStreamBlocks,
744
- codeLines: codeBlockStreamLines,
745
- },
746
- }
747
-
748
- const streamHeadings: StreamingScenarioPlan = {
749
- kind: "streaming",
750
- name: "incremental_headings",
751
- description: "Incremental parsing with appended headings",
752
- iterations: baseIterations,
753
- warmupIterations: baseWarmup,
754
- baseContent: headingStreamBaseContent,
755
- chunks: headingStreamChunks,
756
- repeat: true,
757
- contentStats: {
758
- headings: headingStreamCount,
759
- depthMin: 2,
760
- depthMax: 4,
761
- wordsPerHeading: 4,
762
- },
763
- }
764
-
765
- const styleSmall: StyleScenarioPlan = {
766
- kind: "style",
767
- name: "style_rerender_small",
768
- description: "Rerender blocks on style changes (small document)",
769
- iterations: baseIterations,
770
- warmupIterations: baseWarmup,
771
- content: staticSmallDoc.content,
772
- contentStats: staticSmallDoc.stats,
773
- }
774
-
775
- const styleLarge: StyleScenarioPlan = {
776
- kind: "style",
777
- name: "style_rerender_large",
778
- description: "Rerender blocks on style changes (large document)",
779
- iterations: baseIterations,
780
- warmupIterations: baseWarmup,
781
- content: staticLargeDoc.content,
782
- contentStats: staticLargeDoc.stats,
783
- }
784
-
785
- const styleTableSmall: StyleScenarioPlan = {
786
- kind: "style",
787
- name: "style_rerender_tables_only",
788
- description: "Rerender blocks on style changes (tables-only)",
789
- iterations: baseIterations,
790
- warmupIterations: baseWarmup,
791
- content: tableOnlySmallDoc.content,
792
- contentStats: tableOnlySmallDoc.stats,
793
- }
794
-
795
- if (suite === "quick") return [staticSmall, tableOnlySmall, streamMixed, streamTableRows, styleSmall]
796
- if (suite === "long")
797
- return [
798
- staticLarge,
799
- tableOnlyLarge,
800
- codeOnlyLarge,
801
- streamMixed,
802
- streamTableRows,
803
- streamCodeBlocks,
804
- streamHeadings,
805
- streamTablesLong,
806
- styleLarge,
807
- ]
808
- if (suite === "default")
809
- return [
810
- staticSmall,
811
- tableOnlySmall,
812
- codeOnlySmall,
813
- headingsOnly,
814
- staticLarge,
815
- streamMixed,
816
- streamTableRows,
817
- streamCodeBlocks,
818
- streamHeadings,
819
- styleSmall,
820
- styleTableSmall,
821
- styleLarge,
822
- streamTablesLong,
823
- ]
824
- return []
825
- }
826
-
827
- async function runScenario(plan: ScenarioPlan, ctx: RunContext): Promise<ScenarioResult> {
828
- if (plan.kind === "static") {
829
- return runStaticScenario(plan, ctx)
830
- }
831
- if (plan.kind === "style") {
832
- return runStyleScenario(plan, ctx)
833
- }
834
- return runStreamingScenario(plan, ctx)
835
- }
836
-
837
- async function runStaticScenario(plan: StaticScenarioPlan, ctx: RunContext): Promise<ScenarioResult> {
838
- ctx.markdown.streaming = false
839
- ctx.markdown.content = ""
840
- ctx.markdown.clearCache()
841
-
842
- for (let i = 0; i < plan.warmupIterations; i += 1) {
843
- ctx.markdown.content = ""
844
- ctx.markdown.clearCache()
845
- ctx.markdown.content = plan.content
846
- }
847
-
848
- const durations: number[] = []
849
- const measurementStart = Date.now()
850
- const memStart = shouldSampleMemory(ctx) ? readMemorySample() : null
851
- const nativeMemStart = shouldSampleMemory(ctx) ? readNativeMemorySample() : null
852
- const sampler = createMemorySampler(ctx)
853
-
854
- for (let i = 0; i < plan.iterations; i += 1) {
855
- ctx.markdown.content = ""
856
- ctx.markdown.clearCache()
857
- const start = performance.now()
858
- ctx.markdown.content = plan.content
859
- const elapsed = performance.now() - start
860
- durations.push(elapsed)
861
- sampler.recordIteration(i + 1)
862
- }
863
-
864
- const elapsedMs = Date.now() - measurementStart
865
- const memEnd = shouldSampleMemory(ctx) ? readMemorySample() : null
866
- const nativeMemEnd = shouldSampleMemory(ctx) ? readNativeMemorySample() : null
867
- sampler.stop()
868
-
869
- return {
870
- name: plan.name,
871
- description: plan.description,
872
- iterations: plan.iterations,
873
- warmupIterations: plan.warmupIterations,
874
- elapsedMs,
875
- category: "parse",
876
- timingMode: "content-set",
877
- updateStats: computeTimingStats(durations),
878
- memoryStats: memStart && memEnd ? computeMemoryStats(sampler.jsSamples, memStart, memEnd) : undefined,
879
- nativeMemoryStats:
880
- nativeMemStart && nativeMemEnd
881
- ? computeNativeMemoryStats(sampler.nativeSamples, nativeMemStart, nativeMemEnd)
882
- : undefined,
883
- contentStats: {
884
- initialChars: plan.content.length,
885
- finalChars: plan.content.length,
886
- maxChars: plan.content.length,
887
- updates: plan.iterations,
888
- appendedChars: 0,
889
- },
890
- settings: {
891
- ...plan.contentStats,
892
- mode: "static",
893
- },
894
- }
895
- }
896
-
897
- async function runStreamingScenario(plan: StreamingScenarioPlan, ctx: RunContext): Promise<ScenarioResult> {
898
- ctx.markdown.streaming = true
899
- const state = createStreamState({
900
- content: plan.baseContent,
901
- chunks: plan.chunks,
902
- repeat: plan.repeat,
903
- maxChars: ctx.maxChars,
904
- })
905
-
906
- ctx.markdown.content = state.content
907
-
908
- if (plan.warmupIterations > 0) {
909
- await runStreamingIterations(state, ctx, plan.warmupIterations, false)
910
- }
911
-
912
- const measurementStart = Date.now()
913
- const memStart = shouldSampleMemory(ctx) ? readMemorySample() : null
914
- const nativeMemStart = shouldSampleMemory(ctx) ? readNativeMemorySample() : null
915
- const sampler = createMemorySampler(ctx)
916
-
917
- const measured = await runStreamingIterations(state, ctx, plan.iterations, true, sampler)
918
- if (measured.durations.length < plan.iterations) {
919
- throw new Error(
920
- `streaming scenario '${plan.name}' ended early (updates=${measured.durations.length}/${plan.iterations}). Increase --max-chars or reduce --iterations.`,
921
- )
922
- }
923
-
924
- const elapsedMs = Date.now() - measurementStart
925
- const memEnd = shouldSampleMemory(ctx) ? readMemorySample() : null
926
- const nativeMemEnd = shouldSampleMemory(ctx) ? readNativeMemorySample() : null
927
- sampler.stop()
928
-
929
- return {
930
- name: plan.name,
931
- description: plan.description,
932
- iterations: plan.iterations,
933
- warmupIterations: plan.warmupIterations,
934
- elapsedMs,
935
- category: "incremental",
936
- timingMode: "content-set",
937
- updateStats: computeTimingStats(measured.durations),
938
- memoryStats: memStart && memEnd ? computeMemoryStats(sampler.jsSamples, memStart, memEnd) : undefined,
939
- nativeMemoryStats:
940
- nativeMemStart && nativeMemEnd
941
- ? computeNativeMemoryStats(sampler.nativeSamples, nativeMemStart, nativeMemEnd)
942
- : undefined,
943
- contentStats: {
944
- initialChars: plan.baseContent.length,
945
- finalChars: state.content.length,
946
- maxChars: state.maxContentChars,
947
- updates: measured.durations.length,
948
- appendedChars: measured.appendedChars,
949
- },
950
- settings: {
951
- ...plan.contentStats,
952
- mode: "streaming",
953
- streamIntervalMs: ctx.streamIntervalMs,
954
- appendLinesPerTick: ctx.chunkLines,
955
- maxChars: ctx.maxChars,
956
- repeat: plan.repeat,
957
- },
958
- }
959
- }
960
-
961
- async function runStyleScenario(plan: StyleScenarioPlan, ctx: RunContext): Promise<ScenarioResult> {
962
- ctx.markdown.streaming = false
963
- ctx.markdown.syntaxStyle = ctx.syntaxStyleA
964
- ctx.markdown.conceal = true
965
- ctx.markdown.content = plan.content
966
-
967
- for (let i = 0; i < plan.warmupIterations; i += 1) {
968
- ctx.markdown.conceal = !ctx.markdown.conceal
969
- ctx.markdown.refreshStyles()
970
- }
971
-
972
- const durations: number[] = []
973
- const measurementStart = Date.now()
974
- const memStart = shouldSampleMemory(ctx) ? readMemorySample() : null
975
- const nativeMemStart = shouldSampleMemory(ctx) ? readNativeMemorySample() : null
976
- const sampler = createMemorySampler(ctx)
977
-
978
- for (let i = 0; i < plan.iterations; i += 1) {
979
- ctx.markdown.conceal = !ctx.markdown.conceal
980
- ctx.markdown.syntaxStyle = i % 2 === 0 ? ctx.syntaxStyleA : ctx.syntaxStyleB
981
- const start = performance.now()
982
- ctx.markdown.refreshStyles()
983
- const elapsed = performance.now() - start
984
- durations.push(elapsed)
985
- sampler.recordIteration(i + 1)
986
- }
987
-
988
- const elapsedMs = Date.now() - measurementStart
989
- const memEnd = shouldSampleMemory(ctx) ? readMemorySample() : null
990
- const nativeMemEnd = shouldSampleMemory(ctx) ? readNativeMemorySample() : null
991
- sampler.stop()
992
-
993
- return {
994
- name: plan.name,
995
- description: plan.description,
996
- iterations: plan.iterations,
997
- warmupIterations: plan.warmupIterations,
998
- elapsedMs,
999
- category: "style",
1000
- timingMode: "style-refresh",
1001
- updateStats: computeTimingStats(durations),
1002
- memoryStats: memStart && memEnd ? computeMemoryStats(sampler.jsSamples, memStart, memEnd) : undefined,
1003
- nativeMemoryStats:
1004
- nativeMemStart && nativeMemEnd
1005
- ? computeNativeMemoryStats(sampler.nativeSamples, nativeMemStart, nativeMemEnd)
1006
- : undefined,
1007
- contentStats: {
1008
- initialChars: plan.content.length,
1009
- finalChars: plan.content.length,
1010
- maxChars: plan.content.length,
1011
- updates: plan.iterations,
1012
- appendedChars: 0,
1013
- },
1014
- settings: {
1015
- ...plan.contentStats,
1016
- mode: "style",
1017
- },
1018
- }
1019
- }
1020
-
1021
- async function runStreamingIterations(
1022
- state: StreamState,
1023
- ctx: RunContext,
1024
- iterations: number,
1025
- record: boolean,
1026
- sampler?: MemorySampler,
1027
- ): Promise<{ durations: number[]; appendedChars: number }> {
1028
- const durations: number[] = []
1029
- let appendedChars = 0
1030
-
1031
- for (let i = 0; i < iterations; i += 1) {
1032
- const update = appendStream(state, ctx.chunkLines)
1033
- if (!update.updated) break
1034
-
1035
- const start = performance.now()
1036
- ctx.markdown.content = state.content
1037
- const elapsed = performance.now() - start
1038
-
1039
- if (record) {
1040
- durations.push(elapsed)
1041
- appendedChars += update.appendedChars
1042
- sampler?.recordIteration(durations.length)
1043
- }
1044
-
1045
- if (ctx.streamIntervalMs > 0) {
1046
- await Bun.sleep(ctx.streamIntervalMs)
1047
- }
1048
- }
1049
-
1050
- return { durations, appendedChars }
1051
- }
1052
-
1053
- function createStreamState(input: {
1054
- content: string
1055
- chunks: string[]
1056
- repeat: boolean
1057
- maxChars: number
1058
- }): StreamState {
1059
- return {
1060
- content: input.content,
1061
- chunks: input.chunks,
1062
- cursor: 0,
1063
- repeat: input.repeat,
1064
- maxChars: input.maxChars,
1065
- maxContentChars: input.content.length,
1066
- done: false,
1067
- }
1068
- }
1069
-
1070
- function appendStream(state: StreamState, linesPerTick: number): { updated: boolean; appendedChars: number } {
1071
- if (state.done) return { updated: false, appendedChars: 0 }
1072
- let appended = ""
1073
-
1074
- for (let i = 0; i < linesPerTick; i += 1) {
1075
- if (state.cursor >= state.chunks.length) {
1076
- if (state.repeat) {
1077
- state.cursor = 0
1078
- } else {
1079
- state.done = true
1080
- break
1081
- }
1082
- }
1083
- appended += state.chunks[state.cursor]
1084
- state.cursor += 1
1085
- }
1086
-
1087
- if (!appended) return { updated: false, appendedChars: 0 }
1088
-
1089
- if (state.maxChars > 0 && state.content.length + appended.length > state.maxChars) {
1090
- state.done = true
1091
- return { updated: false, appendedChars: 0 }
1092
- }
1093
-
1094
- state.content += appended
1095
- state.maxContentChars = Math.max(state.maxContentChars, state.content.length)
1096
-
1097
- return { updated: true, appendedChars: appended.length }
1098
- }
1099
-
1100
- function buildMarkdownDocument(rng: () => number, config: StaticScenarioConfig): { content: string; stats: any } {
1101
- const parts: string[] = []
1102
- parts.push(`# ${config.title}`)
1103
-
1104
- for (let section = 0; section < config.sections; section += 1) {
1105
- parts.push(`## Section ${section + 1}`)
1106
-
1107
- for (let p = 0; p < config.paragraphsPerSection; p += 1) {
1108
- parts.push(makeParagraph(rng, config.sentencesPerParagraph))
1109
- }
1110
-
1111
- if (config.lists > 0) {
1112
- for (let l = 0; l < config.lists; l += 1) {
1113
- parts.push(makeList(rng, config.listItems))
1114
- }
1115
- }
1116
-
1117
- if (config.tables > 0) {
1118
- for (let t = 0; t < config.tables; t += 1) {
1119
- const tableLines = makeTableLines(rng, config.tableCols, config.tableRows)
1120
- parts.push(tableLines.join("\n"))
1121
- }
1122
- }
1123
-
1124
- if (config.codeBlocks > 0) {
1125
- for (let c = 0; c < config.codeBlocks; c += 1) {
1126
- parts.push(makeCodeBlock(rng, config.codeLines))
1127
- }
1128
- }
1129
- }
1130
-
1131
- return {
1132
- content: parts.join("\n\n") + "\n",
1133
- stats: {
1134
- sections: config.sections,
1135
- paragraphsPerSection: config.paragraphsPerSection,
1136
- sentencesPerParagraph: config.sentencesPerParagraph,
1137
- listsPerSection: config.lists,
1138
- totalLists: config.sections * config.lists,
1139
- listItems: config.listItems,
1140
- tablesPerSection: config.tables,
1141
- totalTables: config.sections * config.tables,
1142
- tableRows: config.tableRows,
1143
- tableCols: config.tableCols,
1144
- codeBlocksPerSection: config.codeBlocks,
1145
- totalCodeBlocks: config.sections * config.codeBlocks,
1146
- codeLines: config.codeLines,
1147
- totalParagraphs: config.sections * config.paragraphsPerSection,
1148
- },
1149
- }
1150
- }
1151
-
1152
- function buildTableOnlyDocument(
1153
- rng: () => number,
1154
- config: { title: string; tables: number; rows: number; cols: number },
1155
- ): { content: string; stats: any } {
1156
- const parts: string[] = []
1157
- parts.push(`# ${config.title}`)
1158
- for (let t = 0; t < config.tables; t += 1) {
1159
- const tableLines = makeTableLines(rng, config.cols, config.rows)
1160
- parts.push(tableLines.join("\n"))
1161
- }
1162
-
1163
- return {
1164
- content: parts.join("\n\n") + "\n",
1165
- stats: {
1166
- tables: config.tables,
1167
- tableRows: config.rows,
1168
- tableCols: config.cols,
1169
- },
1170
- }
1171
- }
1172
-
1173
- function buildCodeOnlyDocument(
1174
- rng: () => number,
1175
- config: { title: string; blocks: number; lines: number },
1176
- ): { content: string; stats: any } {
1177
- const parts: string[] = []
1178
- parts.push(`# ${config.title}`)
1179
- for (let b = 0; b < config.blocks; b += 1) {
1180
- parts.push(makeCodeBlock(rng, config.lines))
1181
- }
1182
-
1183
- return {
1184
- content: parts.join("\n\n") + "\n",
1185
- stats: {
1186
- codeBlocks: config.blocks,
1187
- codeLines: config.lines,
1188
- },
1189
- }
1190
- }
1191
-
1192
- function buildHeadingsOnlyDocument(
1193
- rng: () => number,
1194
- config: { title: string; headings: number; depthMin: number; depthMax: number; wordsPerHeading: number },
1195
- ): { content: string; stats: any } {
1196
- const parts: string[] = []
1197
- parts.push(`# ${config.title}`)
1198
- for (let i = 0; i < config.headings; i += 1) {
1199
- parts.push(makeHeadingLine(rng, config.depthMin, config.depthMax, config.wordsPerHeading))
1200
- }
1201
-
1202
- return {
1203
- content: parts.join("\n") + "\n",
1204
- stats: {
1205
- headings: config.headings,
1206
- depthMin: config.depthMin,
1207
- depthMax: config.depthMax,
1208
- wordsPerHeading: config.wordsPerHeading,
1209
- },
1210
- }
1211
- }
1212
-
1213
- function buildHeadingChunks(
1214
- rng: () => number,
1215
- config: { headings: number; depthMin: number; depthMax: number; wordsPerHeading: number },
1216
- ): string[] {
1217
- const chunks: string[] = []
1218
- for (let i = 0; i < config.headings; i += 1) {
1219
- chunks.push(makeHeadingLine(rng, config.depthMin, config.depthMax, config.wordsPerHeading) + "\n")
1220
- }
1221
- return chunks
1222
- }
1223
-
1224
- function buildCodeBlockChunks(rng: () => number, config: { blocks: number; lines: number }): string[] {
1225
- const chunks: string[] = []
1226
- for (let b = 0; b < config.blocks; b += 1) {
1227
- const lines = makeCodeBlockLines(rng, config.lines)
1228
- for (const line of lines) {
1229
- chunks.push(`${line}\n`)
1230
- }
1231
- chunks.push("\n")
1232
- }
1233
- return chunks
1234
- }
1235
-
1236
- function buildTableRowChunks(rng: () => number, config: { rows: number; cols: number }): string[] {
1237
- const chunks: string[] = []
1238
- for (let r = 0; r < config.rows; r += 1) {
1239
- chunks.push(makeTableRowLine(rng, r, config.cols) + "\n")
1240
- }
1241
- return chunks
1242
- }
1243
-
1244
- function buildStreamingChunks(rng: () => number, config: StreamingScenarioConfig): string[] {
1245
- const chunks: string[] = []
1246
- for (let section = 0; section < config.sections; section += 1) {
1247
- pushLine(chunks, `### Stream Section ${section + 1}`)
1248
- pushLine(chunks, "")
1249
-
1250
- for (let p = 0; p < config.paragraphsPerSection; p += 1) {
1251
- pushLine(chunks, makeParagraph(rng, config.sentencesPerParagraph))
1252
- pushLine(chunks, "")
1253
- }
1254
-
1255
- for (let l = 0; l < config.lists; l += 1) {
1256
- const listLines = makeListLines(rng, config.listItems)
1257
- for (const line of listLines) {
1258
- pushLine(chunks, line)
1259
- }
1260
- pushLine(chunks, "")
1261
- }
1262
-
1263
- for (let t = 0; t < config.tables; t += 1) {
1264
- const tableLines = makeTableLines(rng, config.tableCols, config.tableRows)
1265
- for (const line of tableLines) {
1266
- pushLine(chunks, line)
1267
- }
1268
- pushLine(chunks, "")
1269
- }
1270
-
1271
- for (let c = 0; c < config.codeBlocks; c += 1) {
1272
- const codeLines = makeCodeBlockLines(rng, config.codeLines)
1273
- for (const line of codeLines) {
1274
- pushLine(chunks, line)
1275
- }
1276
- pushLine(chunks, "")
1277
- }
1278
- }
1279
-
1280
- return chunks
1281
- }
1282
-
1283
- function pushLine(chunks: string[], line: string): void {
1284
- chunks.push(`${line}\n`)
1285
- }
1286
-
1287
- function makeParagraph(rng: () => number, sentences: number): string {
1288
- const parts: string[] = []
1289
- for (let i = 0; i < sentences; i += 1) {
1290
- parts.push(makeSentence(rng, 6, 12))
1291
- }
1292
- return parts.join(" ")
1293
- }
1294
-
1295
- function makeSentence(rng: () => number, minWords: number, maxWords: number): string {
1296
- const count = minWords + Math.floor(rng() * (maxWords - minWords + 1))
1297
- const words: string[] = []
1298
- for (let i = 0; i < count; i += 1) {
1299
- let word = pick(rng, WORDS)
1300
- if (rng() < 0.25) {
1301
- word = wrapInline(rng, word)
1302
- }
1303
- words.push(word)
1304
- }
1305
- const sentence = words.join(" ")
1306
- return sentence.charAt(0).toUpperCase() + sentence.slice(1) + "."
1307
- }
1308
-
1309
- function wrapInline(rng: () => number, word: string): string {
1310
- const roll = rng()
1311
- if (roll < 0.08) return `**${word}**`
1312
- if (roll < 0.16) return `*${word}*`
1313
- if (roll < 0.22) return `\`${word}\``
1314
- if (roll < 0.26) return `[${word}](https://example.com/${word})`
1315
- return word
1316
- }
1317
-
1318
- function makeList(rng: () => number, items: number): string {
1319
- return makeListLines(rng, items).join("\n")
1320
- }
1321
-
1322
- function makeListLines(rng: () => number, items: number): string[] {
1323
- const lines: string[] = []
1324
- for (let i = 0; i < items; i += 1) {
1325
- lines.push(`- ${makeSentence(rng, 4, 9)}`)
1326
- }
1327
- return lines
1328
- }
1329
-
1330
- function makeCodeBlock(rng: () => number, lines: number): string {
1331
- return makeCodeBlockLines(rng, lines).join("\n")
1332
- }
1333
-
1334
- function makeCodeBlockLines(rng: () => number, lines: number): string[] {
1335
- const variable = pick(rng, CODE_WORDS)
1336
- const iterations = Math.max(2, Math.floor(lines / 2))
1337
- const targetLines = Math.max(6, lines)
1338
- const body: string[] = []
1339
- body.push(`const ${variable} = ${Math.floor(rng() * 1000)}`)
1340
- body.push(`let result = ${Math.floor(rng() * 10)}`)
1341
- body.push(`for (let i = 0; i < ${iterations}; i += 1) {`)
1342
- body.push(` result += (${variable} + i) % 5`)
1343
- body.push("}")
1344
- body.push("return result")
1345
-
1346
- let fillerIndex = 0
1347
- while (body.length < targetLines) {
1348
- body.splice(body.length - 1, 0, `result += ${Math.floor(rng() * 10)} + ${fillerIndex}`)
1349
- fillerIndex += 1
1350
- }
1351
-
1352
- return ["```typescript", ...body, "```"]
1353
- }
1354
-
1355
- function makeTableLines(rng: () => number, columns: number, rows: number): string[] {
1356
- const header: string[] = []
1357
- const align: string[] = []
1358
-
1359
- for (let c = 0; c < columns; c += 1) {
1360
- header.push(`Column ${c + 1}`)
1361
- if (c % 3 === 0) align.push(":---")
1362
- else if (c % 3 === 1) align.push(":---:")
1363
- else align.push("---:")
1364
- }
1365
-
1366
- const lines: string[] = []
1367
- lines.push(`| ${header.join(" | ")} |`)
1368
- lines.push(`| ${align.join(" | ")} |`)
1369
-
1370
- for (let r = 0; r < rows; r += 1) {
1371
- const cells: string[] = []
1372
- for (let c = 0; c < columns; c += 1) {
1373
- cells.push(makeCellText(rng, r, c))
1374
- }
1375
- lines.push(`| ${cells.join(" | ")} |`)
1376
- }
1377
-
1378
- return lines
1379
- }
1380
-
1381
- function makeTableRowLine(rng: () => number, row: number, columns: number): string {
1382
- const cells: string[] = []
1383
- for (let c = 0; c < columns; c += 1) {
1384
- cells.push(makeCellText(rng, row, c))
1385
- }
1386
- return `| ${cells.join(" | ")} |`
1387
- }
1388
-
1389
- function makeHeadingLine(rng: () => number, depthMin: number, depthMax: number, words: number): string {
1390
- const depth = depthMin + Math.floor(rng() * Math.max(1, depthMax - depthMin + 1))
1391
- const tokens: string[] = []
1392
- for (let i = 0; i < words; i += 1) {
1393
- tokens.push(pick(rng, WORDS))
1394
- }
1395
- return `${"#".repeat(depth)} ${tokens.join(" ")}`
1396
- }
1397
-
1398
- function makeCellText(rng: () => number, row: number, col: number): string {
1399
- const base = `${pick(rng, WORDS)} ${pick(rng, WORDS)}`
1400
- const roll = rng()
1401
- if (roll < 0.2) return `**${base}**`
1402
- if (roll < 0.35) return `*${base}*`
1403
- if (roll < 0.45) return `\`${base}\``
1404
- if (roll < 0.55) return `${base} ${Math.floor(rng() * 100)}`
1405
- if (roll < 0.6) return `[${base}](https://example.com/r${row}c${col})`
1406
- return base
1407
- }
1408
-
1409
- function pick<T>(rng: () => number, list: T[]): T {
1410
- return list[Math.floor(rng() * list.length)]
1411
- }
1412
-
1413
- function scaled(value: number, scaleValue: number): number {
1414
- return Math.max(1, Math.round(value * scaleValue))
1415
- }
1416
-
1417
- function createRng(initialSeed: number): () => number {
1418
- let state = initialSeed >>> 0
1419
- return () => {
1420
- state = (state * 1664525 + 1013904223) >>> 0
1421
- return state / 0x100000000
1422
- }
1423
- }
1424
-
1425
- function toNumber(value: unknown, fallback: number): number {
1426
- if (typeof value === "number" && Number.isFinite(value)) return value
1427
- if (typeof value === "string") {
1428
- const parsed = Number(value)
1429
- if (Number.isFinite(parsed)) return parsed
1430
- }
1431
- return fallback
1432
- }
1433
-
1434
- function shouldSampleMemory(ctx: RunContext): boolean {
1435
- return ctx.memInterval > 0 || ctx.memSampleEvery > 0
1436
- }
1437
-
1438
- function readMemorySample(): MemorySample {
1439
- const usage = process.memoryUsage()
1440
- return {
1441
- rss: usage.rss ?? 0,
1442
- heapTotal: usage.heapTotal ?? 0,
1443
- heapUsed: usage.heapUsed ?? 0,
1444
- external: usage.external ?? 0,
1445
- arrayBuffers: usage.arrayBuffers ?? 0,
1446
- }
1447
- }
1448
-
1449
- function readNativeMemorySample(): NativeMemorySample {
1450
- const stats = nativeLib.getAllocatorStats()
1451
- return {
1452
- totalRequestedBytes: stats.totalRequestedBytes,
1453
- activeAllocations: stats.activeAllocations,
1454
- smallAllocations: stats.smallAllocations,
1455
- largeAllocations: stats.largeAllocations,
1456
- requestedBytesValid: stats.requestedBytesValid,
1457
- }
1458
- }
1459
-
1460
- function createMemorySampler(ctx: RunContext): MemorySampler {
1461
- const jsSamples: MemorySample[] = []
1462
- const nativeSamples: NativeMemorySample[] = []
1463
-
1464
- const pushSample = (): void => {
1465
- jsSamples.push(readMemorySample())
1466
- nativeSamples.push(readNativeMemorySample())
1467
- }
1468
-
1469
- if (ctx.memInterval > 0) {
1470
- const timer = setInterval(() => {
1471
- pushSample()
1472
- }, ctx.memInterval)
1473
- return {
1474
- jsSamples,
1475
- nativeSamples,
1476
- recordIteration: () => {},
1477
- stop: () => clearInterval(timer),
1478
- }
1479
- }
1480
-
1481
- if (ctx.memSampleEvery > 0) {
1482
- return {
1483
- jsSamples,
1484
- nativeSamples,
1485
- recordIteration: (iteration: number) => {
1486
- if (iteration % ctx.memSampleEvery === 0) {
1487
- pushSample()
1488
- }
1489
- },
1490
- stop: () => {},
1491
- }
1492
- }
1493
-
1494
- return {
1495
- jsSamples,
1496
- nativeSamples,
1497
- recordIteration: () => {},
1498
- stop: () => {},
1499
- }
1500
- }
1501
-
1502
- function computeMemoryStats(samples: MemorySample[], start: MemorySample, end: MemorySample): MemoryStats {
1503
- const all = [start, ...samples, end]
1504
- const peak = { ...start }
1505
- for (const sample of all) {
1506
- updatePeak(sample, peak)
1507
- }
1508
-
1509
- return {
1510
- samples: all.length,
1511
- start,
1512
- end,
1513
- delta: diffMemory(start, end),
1514
- peak,
1515
- fields: {
1516
- rss: computeFieldStats(all.map((s) => s.rss)),
1517
- heapTotal: computeFieldStats(all.map((s) => s.heapTotal)),
1518
- heapUsed: computeFieldStats(all.map((s) => s.heapUsed)),
1519
- external: computeFieldStats(all.map((s) => s.external)),
1520
- arrayBuffers: computeFieldStats(all.map((s) => s.arrayBuffers)),
1521
- },
1522
- }
1523
- }
1524
-
1525
- function computeNativeMemoryStats(
1526
- samples: NativeMemorySample[],
1527
- start: NativeMemorySample,
1528
- end: NativeMemorySample,
1529
- ): NativeMemoryStats {
1530
- const all = [start, ...samples, end]
1531
- const requestedBytesReliable = all.every((sample) => sample.requestedBytesValid)
1532
- const peak = { ...start }
1533
- for (const sample of all) {
1534
- updateNativePeak(sample, peak)
1535
- }
1536
-
1537
- return {
1538
- samples: all.length,
1539
- start,
1540
- end,
1541
- delta: diffNativeMemory(start, end),
1542
- peak,
1543
- requestedBytesReliable,
1544
- fields: {
1545
- totalRequestedBytes: computeFieldStats(all.map((s) => s.totalRequestedBytes)),
1546
- activeAllocations: computeFieldStats(all.map((s) => s.activeAllocations)),
1547
- smallAllocations: computeFieldStats(all.map((s) => s.smallAllocations)),
1548
- largeAllocations: computeFieldStats(all.map((s) => s.largeAllocations)),
1549
- },
1550
- }
1551
- }
1552
-
1553
- function updatePeak(sample: MemorySample, peak: MemorySample): void {
1554
- peak.rss = Math.max(peak.rss, sample.rss)
1555
- peak.heapTotal = Math.max(peak.heapTotal, sample.heapTotal)
1556
- peak.heapUsed = Math.max(peak.heapUsed, sample.heapUsed)
1557
- peak.external = Math.max(peak.external, sample.external)
1558
- peak.arrayBuffers = Math.max(peak.arrayBuffers, sample.arrayBuffers)
1559
- }
1560
-
1561
- function updateNativePeak(sample: NativeMemorySample, peak: NativeMemorySample): void {
1562
- peak.totalRequestedBytes = Math.max(peak.totalRequestedBytes, sample.totalRequestedBytes)
1563
- peak.activeAllocations = Math.max(peak.activeAllocations, sample.activeAllocations)
1564
- peak.smallAllocations = Math.max(peak.smallAllocations, sample.smallAllocations)
1565
- peak.largeAllocations = Math.max(peak.largeAllocations, sample.largeAllocations)
1566
- peak.requestedBytesValid = peak.requestedBytesValid && sample.requestedBytesValid
1567
- }
1568
-
1569
- function diffMemory(start: MemorySample, end: MemorySample): MemorySample {
1570
- return {
1571
- rss: end.rss - start.rss,
1572
- heapTotal: end.heapTotal - start.heapTotal,
1573
- heapUsed: end.heapUsed - start.heapUsed,
1574
- external: end.external - start.external,
1575
- arrayBuffers: end.arrayBuffers - start.arrayBuffers,
1576
- }
1577
- }
1578
-
1579
- function diffNativeMemory(start: NativeMemorySample, end: NativeMemorySample): NativeMemorySample {
1580
- return {
1581
- totalRequestedBytes: end.totalRequestedBytes - start.totalRequestedBytes,
1582
- activeAllocations: end.activeAllocations - start.activeAllocations,
1583
- smallAllocations: end.smallAllocations - start.smallAllocations,
1584
- largeAllocations: end.largeAllocations - start.largeAllocations,
1585
- requestedBytesValid: start.requestedBytesValid && end.requestedBytesValid,
1586
- }
1587
- }
1588
-
1589
- function computeFieldStats(values: number[]): MemoryFieldStats {
1590
- const sorted = [...values].sort((a, b) => a - b)
1591
- const min = sorted[0] ?? 0
1592
- const max = sorted[sorted.length - 1] ?? 0
1593
- const avg = sorted.length > 0 ? sorted.reduce((sum, v) => sum + v, 0) / sorted.length : 0
1594
- const median = sorted.length > 0 ? (sorted[Math.floor(sorted.length / 2)] ?? 0) : 0
1595
- return { min, max, avg, median }
1596
- }
1597
-
1598
- function computeTimingStats(durations: number[]): TimingStats {
1599
- const sorted = [...durations].sort((a, b) => a - b)
1600
- const count = sorted.length
1601
- const sum = sorted.reduce((acc, value) => acc + value, 0)
1602
- const average = count > 0 ? sum / count : 0
1603
- const min = sorted[0] ?? 0
1604
- const max = sorted[count - 1] ?? 0
1605
- const median = count > 0 ? (sorted[Math.floor(count / 2)] ?? 0) : 0
1606
- const p95 = count > 0 ? (sorted[Math.floor(count * 0.95)] ?? 0) : 0
1607
- const stdDev = count > 0 ? Math.sqrt(sorted.reduce((acc, v) => acc + Math.pow(v - average, 2), 0) / count) : 0
1608
-
1609
- return {
1610
- count,
1611
- averageMs: average,
1612
- medianMs: median,
1613
- p95Ms: p95,
1614
- minMs: min,
1615
- maxMs: max,
1616
- stdDevMs: stdDev,
1617
- }
1618
- }
1619
-
1620
- async function outputResults(
1621
- meta: OutputMeta,
1622
- resultsList: ScenarioResult[],
1623
- scenarioLines: string[],
1624
- outputEnabled: boolean,
1625
- outputPath: string | null,
1626
- ): Promise<void> {
1627
- const runId = new Date().toISOString()
1628
- const payload = {
1629
- runId,
1630
- suite: meta.suiteName,
1631
- renderer: {
1632
- targetFps: meta.targetFps,
1633
- maxFps: meta.maxFps,
1634
- },
1635
- config: {
1636
- iterations: meta.iterations,
1637
- warmupIterations: meta.warmupIterations,
1638
- longIterations: meta.longIterations,
1639
- streamIntervalMs: meta.streamIntervalMs,
1640
- chunkLines: meta.chunkLines,
1641
- maxChars: meta.maxChars,
1642
- scale: meta.scale,
1643
- seed: meta.seed,
1644
- memInterval: meta.memInterval,
1645
- memSampleEvery: meta.memSampleEvery,
1646
- gpaSafeStats: meta.gpaSafeStats,
1647
- gpaMemoryLimitTracking: meta.gpaMemoryLimitTracking,
1648
- },
1649
- results: resultsList,
1650
- }
1651
-
1652
- if (outputEnabled) {
1653
- writeLine(
1654
- `markdown-benchmark suite=${meta.suiteName} timing=frame-independent iters=${meta.iterations} warmup=${meta.warmupIterations}`,
1655
- )
1656
- writeLine(`native-build gpaSafeStats=${meta.gpaSafeStats} gpaMemoryLimitTracking=${meta.gpaMemoryLimitTracking}`)
1657
- for (const line of scenarioLines) {
1658
- writeLine(line)
1659
- }
1660
- }
1661
-
1662
- if (outputPath) {
1663
- try {
1664
- const json = JSON.stringify(payload, null, 2)
1665
- await Bun.write(outputPath, json)
1666
- } catch (error: any) {
1667
- writeLine(`Error writing results to ${outputPath}: ${error.message}`)
1668
- }
1669
- }
1670
- }
1671
-
1672
- function formatBytes(value: number): string {
1673
- const units = ["B", "KB", "MB", "GB", "TB", "PB"]
1674
- const abs = Math.abs(value)
1675
-
1676
- if (abs < 1024) {
1677
- return `${Math.trunc(value)}B`
1678
- }
1679
-
1680
- let unitIndex = 0
1681
- let scaled = abs
1682
- while (scaled >= 1024 && unitIndex < units.length - 1) {
1683
- scaled /= 1024
1684
- unitIndex += 1
1685
- }
1686
-
1687
- const sign = value < 0 ? "-" : ""
1688
- return `${sign}${scaled.toFixed(2)}${units[unitIndex]}`
1689
- }
1690
-
1691
- function formatAllocs(value: number): string {
1692
- const intValue = Math.trunc(value)
1693
- const sign = intValue > 0 ? "+" : ""
1694
- return `${sign}${intValue.toLocaleString("en-US")} allocs`
1695
- }
1696
-
1697
- function formatScenarioResult(result: ScenarioResult): string {
1698
- const jsMem = result.memoryStats
1699
- const nativeMem = result.nativeMemoryStats
1700
-
1701
- const jsMemSummary = jsMem
1702
- ? ` jsMemDeltaRss=${formatBytes(jsMem.delta.rss)}` +
1703
- ` jsMemDeltaHeap=${formatBytes(jsMem.delta.heapUsed)}` +
1704
- ` jsMemDeltaExt=${formatBytes(jsMem.delta.external)}` +
1705
- ` jsMemDeltaAB=${formatBytes(jsMem.delta.arrayBuffers)}` +
1706
- ` jsMemPeakRss=${formatBytes(jsMem.peak.rss)}`
1707
- : ""
1708
-
1709
- const nativeMemSummary = nativeMem
1710
- ? ` nativeMemDeltaReq=${nativeMem.requestedBytesReliable ? formatBytes(nativeMem.delta.totalRequestedBytes) : "invalid"}` +
1711
- ` nativeMemDeltaReqBytes=${nativeMem.requestedBytesReliable ? `${Math.trunc(nativeMem.delta.totalRequestedBytes)}B` : "invalid"}` +
1712
- ` nativeMemDeltaActive=${formatAllocs(nativeMem.delta.activeAllocations)}` +
1713
- ` nativeMemDeltaSmall=${formatAllocs(nativeMem.delta.smallAllocations)}` +
1714
- ` nativeMemDeltaLarge=${formatAllocs(nativeMem.delta.largeAllocations)}` +
1715
- ` nativeMemPeakReq=${nativeMem.requestedBytesReliable ? formatBytes(nativeMem.peak.totalRequestedBytes) : "invalid"}` +
1716
- ` nativeMemPeakReqBytes=${nativeMem.requestedBytesReliable ? `${Math.trunc(nativeMem.peak.totalRequestedBytes)}B` : "invalid"}` +
1717
- ` nativeMemPeakActive=${formatAllocs(nativeMem.peak.activeAllocations)}` +
1718
- ` nativeMemReqReliable=${nativeMem.requestedBytesReliable}`
1719
- : ""
1720
-
1721
- return `scenario=${result.name} category=${result.category} mode=${result.timingMode} iters=${result.updateStats.count} elapsedMs=${result.elapsedMs} avgMs=${result.updateStats.averageMs.toFixed(3)} medianMs=${result.updateStats.medianMs.toFixed(3)} p95Ms=${result.updateStats.p95Ms.toFixed(3)} minMs=${result.updateStats.minMs.toFixed(3)} maxMs=${result.updateStats.maxMs.toFixed(3)} chars=${result.contentStats.finalChars}${jsMemSummary}${nativeMemSummary}`
1722
- }
1723
-
1724
- function writeLine(line: string): void {
1725
- realStdoutWrite(`${line}\n`)
1726
- }
1727
-
1728
- async function runSpawnedScenarios(plans: ScenarioPlan[]): Promise<void> {
1729
- const tempDir = await mkdtemp(path.join(tmpdir(), "opentui-markdown-bench-"))
1730
- const scenarioLines: string[] = []
1731
- const results: ScenarioResult[] = []
1732
-
1733
- for (const plan of plans) {
1734
- const jsonPath = path.join(tempDir, `scenario-${plan.name}.json`)
1735
- const args = buildChildArgs(process.argv.slice(2), plan.name, jsonPath)
1736
- const child = Bun.spawn([process.execPath, new URL(import.meta.url).pathname, ...args], {
1737
- stdout: "inherit",
1738
- stderr: "inherit",
1739
- env: process.env,
1740
- })
1741
- const exitCode = await child.exited
1742
- if (exitCode !== 0) {
1743
- throw new Error(`Scenario ${plan.name} failed with exit code ${exitCode}`)
1744
- }
1745
-
1746
- const json = await readFile(jsonPath, "utf8")
1747
- await unlink(jsonPath)
1748
- const payload = JSON.parse(json)
1749
- const result = payload.results?.[0] as ScenarioResult | undefined
1750
- if (!result) {
1751
- throw new Error(`Scenario ${plan.name} did not produce a result`)
1752
- }
1753
- results.push(result)
1754
- scenarioLines.push(formatScenarioResult(result))
1755
- }
1756
-
1757
- await outputResults(
1758
- {
1759
- suiteName,
1760
- targetFps,
1761
- maxFps,
1762
- iterations,
1763
- warmupIterations,
1764
- longIterations,
1765
- streamIntervalMs,
1766
- chunkLines,
1767
- maxChars,
1768
- scale,
1769
- seed,
1770
- memInterval,
1771
- memSampleEvery,
1772
- gpaSafeStats: nativeBuildOptions.gpaSafeStats,
1773
- gpaMemoryLimitTracking: nativeBuildOptions.gpaMemoryLimitTracking,
1774
- },
1775
- results,
1776
- scenarioLines,
1777
- outputEnabled,
1778
- jsonPath,
1779
- )
1780
- }
1781
-
1782
- function buildChildArgs(args: string[], scenarioName: string, jsonPath: string): string[] {
1783
- const filtered: string[] = []
1784
- for (const arg of args) {
1785
- if (arg === "--no-spawn-per-scenario") continue
1786
- if (arg.startsWith("--scenario")) continue
1787
- if (arg === "--json" || arg.startsWith("--json=")) continue
1788
- if (arg === "--output" || arg === "--no-output") continue
1789
- filtered.push(arg)
1790
- }
1791
- filtered.push(`--scenario=${scenarioName}`)
1792
- filtered.push(`--json=${jsonPath}`)
1793
- filtered.push("--no-output")
1794
- filtered.push("--no-spawn-per-scenario")
1795
- return filtered
1796
- }