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