-
-
Notifications
You must be signed in to change notification settings - Fork 945
feat(XMarkdown): streaming markdown benchmark #1314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Div627
wants to merge
21
commits into
feature
Choose a base branch
from
feature_markdown_benchmark
base: feature
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
21cd0a3
feat: streaming markdown benchmark
657aff5
feat: modify benchmark
50a7916
feat: react-markdown
83757be
Merge remote-tracking branch 'origin/next' into feature_markdown_benc…
ae706c6
feat: finsih streaming markdown performance markdown via playwright
eb94725
Merge remote-tracking branch 'origin/next' into feature_markdown_benc…
Div627 100c8e6
feat: benchmark
Div627 db7d085
Merge remote-tracking branch 'origin/next' into feature_markdown_benc…
Div627 cda8b53
fix: fix type
Div627 60120d6
docs: animation docs
Div627 7151f45
docs: animation docs
Div627 db8b477
Merge remote-tracking branch 'origin/next' into feature_markdown_benc…
Div627 a414080
fix: fix ci
Div627 4e9c528
chore: modify benchmark dependece
Div627 254601b
fix: fix cr
Div627 d95896e
Merge remote-tracking branch 'origin/next' into feature_markdown_benc…
Div627 8358c5b
Merge remote-tracking branch 'origin/feature' into feature_markdown_b…
Div627 1c0cf38
feat: change benmark config
Div627 d0659db
Merge branch 'feature' into feature_markdown_benchmark
Div627 7cae0a2
fix: fix ci
Div627 c450fbe
Merge branch 'feature' into feature_markdown_benchmark
Div627 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
|
|
||
| # Playwright | ||
| node_modules/ | ||
| /test-results/ | ||
| /playwright-report/ | ||
| /blob-report/ | ||
| /playwright/.cache/ | ||
| /playwright/.auth/ |
45 changes: 45 additions & 0 deletions
45
packages/x-markdown/benchmark/components/MarkdownRenderer.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import MarkdownIt from 'markdown-it'; | ||
| import { marked } from 'marked'; | ||
| import React, { FC } from 'react'; | ||
| import ReactMarkdown from 'react-markdown'; | ||
| import { Streamdown } from 'streamdown'; | ||
| import XMarkdown from '../../src'; | ||
|
|
||
| type MarkdownRendererProps = { | ||
| md: string; | ||
| }; | ||
|
|
||
| const MarkedRenderer: FC<MarkdownRendererProps> = (props) => ( | ||
| // biome-ignore lint/security/noDangerouslySetInnerHtml: benchmark only | ||
| <div dangerouslySetInnerHTML={{ __html: marked.parse(props.md) as string }} /> | ||
| ); | ||
|
|
||
| const MarkdownItRenderer: FC<MarkdownRendererProps> = (props) => { | ||
| const md = new MarkdownIt(); | ||
|
|
||
| return ( | ||
| // biome-ignore lint/security/noDangerouslySetInnerHtml: benchmark only | ||
| <div dangerouslySetInnerHTML={{ __html: md.render(props.md) }} /> | ||
| ); | ||
| }; | ||
|
|
||
| const ReactMarkdownRenderer: FC<MarkdownRendererProps> = (props) => ( | ||
| <ReactMarkdown>{props.md}</ReactMarkdown> | ||
| ); | ||
|
|
||
| const XMarkdownRenderer: FC<MarkdownRendererProps> = (props) => <XMarkdown>{props.md}</XMarkdown>; | ||
|
|
||
| const StreamdownRenderer: FC<MarkdownRendererProps> = (props) => ( | ||
| <Streamdown>{props.md}</Streamdown> | ||
| ); | ||
|
|
||
| const Empty = () => <div />; | ||
|
|
||
| export { | ||
| MarkedRenderer, | ||
| MarkdownItRenderer, | ||
| ReactMarkdownRenderer, | ||
| XMarkdownRenderer, | ||
| StreamdownRenderer, | ||
| Empty, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| { | ||
| "name": "streaming-markdown-benchmark", | ||
| "version": "1.0.0", | ||
| "description": "Streaming Markdown performance comparison", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "start-react": "vite --config src/react-app/vite.config.js", | ||
| "test:all": "playwright test -c playwright-ct.config.ts", | ||
| "setup": "node scripts/setup.js", | ||
| "test-ct": "playwright test -c playwright-ct.config.ts" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "devDependencies": { | ||
| "@ant-design/x": "^2.0.0-alpha.15", | ||
| "@ant-design/x-markdown": "^2.0.0-alpha.15", | ||
| "@playwright/experimental-ct-react": "^1.56.1", | ||
| "@playwright/test": "^1.48.2", | ||
| "@types/markdown-it": "^14.0.0", | ||
| "@types/marked": "^6.0.0", | ||
| "@types/node": "^20.10.3", | ||
| "@vitejs/plugin-react": "^4.2.1", | ||
| "antd": "6.0.0-alpha.4", | ||
| "markdown-it": "^14.0.0", | ||
| "marked": "^11.1.1", | ||
| "react": "^18.2.0", | ||
| "react-dom": "^18.2.0", | ||
| "react-markdown": "^9.0.1", | ||
| "streamdown": "^1.4.0", | ||
| "typescript": "^5.3.2", | ||
| "vite": "^5.0.6" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { defineConfig, devices } from '@playwright/experimental-ct-react'; | ||
|
|
||
| /** | ||
| * See https://playwright.dev/docs/test-configuration. | ||
| */ | ||
| export default defineConfig({ | ||
| testDir: './', | ||
| /* The base directory, relative to the config file, for snapshot files created with toMatchSnapshot and toHaveScreenshot. */ | ||
| snapshotDir: './__snapshots__', | ||
| /* Maximum time one test can run for. */ | ||
| timeout: 10 * 1000, | ||
| /* Run tests in files in parallel */ | ||
| fullyParallel: true, | ||
| /* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
| forbidOnly: !!process.env.CI, | ||
| /* Retry on CI only */ | ||
| retries: process.env.CI ? 2 : 0, | ||
| /* Opt out of parallel tests on CI. */ | ||
| workers: process.env.CI ? 1 : undefined, | ||
| /* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
| reporter: 'html', | ||
| /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
| use: { | ||
| /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
| trace: 'on-first-retry', | ||
|
|
||
| /* Port to use for Playwright component endpoint. */ | ||
| ctPort: 3100, | ||
| }, | ||
|
|
||
| /* Configure projects for major browsers */ | ||
| projects: [ | ||
| { | ||
| name: 'chromium', | ||
| use: { ...devices['Desktop Chrome'] }, | ||
| }, | ||
| ], | ||
| }); |
12 changes: 12 additions & 0 deletions
12
packages/x-markdown/benchmark/playwright/.cache/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Testing Page</title> | ||
| <script type="module" crossorigin src="/assets/index-Bw4ETuhr.js"></script> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Testing Page</title> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script type="module" src="./index.tsx"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // Import styles, initialize component theme here. | ||
| // import '../src/common.css'; |
183 changes: 183 additions & 0 deletions
183
packages/x-markdown/benchmark/tests/performance.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,183 @@ | ||||||
| import { test } from '@playwright/experimental-ct-react'; | ||||||
| import fs from 'fs'; | ||||||
| import path from 'path'; | ||||||
| import React from 'react'; | ||||||
| import { | ||||||
| Empty, | ||||||
| MarkdownItRenderer, | ||||||
| MarkedRenderer, | ||||||
| ReactMarkdownRenderer, | ||||||
| StreamdownRenderer, | ||||||
| XMarkdownRenderer, | ||||||
| } from '../components/MarkdownRenderer'; | ||||||
|
|
||||||
| interface BenchmarkResult { | ||||||
| name: string; | ||||||
| duration: number; | ||||||
| avgFPS: number; | ||||||
| minFPS: number; | ||||||
| maxFPS: number; | ||||||
| maxMemory: number; | ||||||
| avgMemory: number; | ||||||
| totalFrames: number; | ||||||
| } | ||||||
|
|
||||||
| const fullText = fs.readFileSync(path.resolve(__dirname, 'test.md'), 'utf-8'); | ||||||
|
|
||||||
| const renderers = ['marked', 'markdown-it', 'react-markdown', 'x-markdown', 'streamdown']; | ||||||
|
|
||||||
| const getRenderer = (name: string, md = '') => { | ||||||
| switch (name) { | ||||||
| case 'marked': { | ||||||
| return <MarkedRenderer md={md} />; | ||||||
| } | ||||||
| case 'markdown-it': { | ||||||
| return <MarkdownItRenderer md={md} />; | ||||||
| } | ||||||
| case 'react-markdown': { | ||||||
| return <ReactMarkdownRenderer md={md} />; | ||||||
| } | ||||||
| case 'x-markdown': { | ||||||
| return <XMarkdownRenderer md={md} />; | ||||||
| } | ||||||
| case 'streamdown': { | ||||||
| return <StreamdownRenderer md={md} />; | ||||||
| } | ||||||
| default: { | ||||||
| return <div>{md}</div>; | ||||||
| } | ||||||
| } | ||||||
| }; | ||||||
|
|
||||||
| async function measure({ | ||||||
| page, | ||||||
| name, | ||||||
| browserName, | ||||||
| mount, | ||||||
| }: { | ||||||
| name: string; | ||||||
| page: any; | ||||||
| mount: any; | ||||||
| browserName: string; | ||||||
| }): Promise<BenchmarkResult> { | ||||||
Div627 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| console.log('🚀 start measure performance:', name); | ||||||
|
|
||||||
| await page.context().tracing.start({ | ||||||
| screenshots: true, | ||||||
| title: `XMarkdown_Stream_Perf_${browserName}`, | ||||||
|
||||||
| title: `XMarkdown_Stream_Perf_${browserName}`, | |
| title: `XMarkdown_Stream_Perf_${name}_${browserName}`, |
Div627 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Div627 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Div627 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Div627 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Div627 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Div627 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.