Skip to content

Conversation

@Div627
Copy link
Contributor

@Div627 Div627 commented Nov 10, 2025

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

This PR implements the benchmark proposed in the RFC:

  • RFC Discussion: #1313
  • RFC Title: "[RFC] 流式 Markdown Benchmark"

💡 Background and Solution

  • 本方案提出一个基于 Playwright Component Testing 的标准化流式 Markdown 渲染性能基准测试,通过统一接口、标准数据集和自动化指标采集,填补前端生态在增量渲染场景下缺乏可量化、可复现性能评估工具的空白,支持 CI 集成与技术选型。

📝 Change Log

  • 基于 Playwright Component Testing 实现流式 Markdown 渲染性能基准测试。
Language Changelog
🇺🇸 English
🇨🇳 Chinese

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 10, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature_markdown_benchmark

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2025

Preview is ready

@dosubot dosubot bot added the enhancement New feature or request label Nov 10, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Div627, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new, standardized performance benchmark for streaming Markdown rendering. It utilizes Playwright Component Testing to automate the measurement of various Markdown libraries, including x-markdown, marked, markdown-it, react-markdown, and streamdown. The goal is to provide quantifiable metrics like duration, FPS, and memory usage for incremental rendering scenarios, which will be valuable for continuous integration and informed technology selection within the frontend ecosystem.

Highlights

  • New Benchmark Suite: Introduced a new performance benchmark suite specifically designed for streaming Markdown rendering, addressing a gap in quantifiable performance evaluation for incremental rendering.
  • Playwright Integration: The benchmark leverages Playwright Component Testing for standardized and automated collection of performance metrics, ensuring reproducible results.
  • Comprehensive Comparison: The suite compares the performance of x-markdown against other popular Markdown rendering libraries, including marked, markdown-it, react-markdown, and streamdown.
  • Robust Test Data: A large and complex test.md file has been added to serve as a standardized dataset, simulating real-world Markdown content to stress-test parsers effectively.
  • Metric Collection: The benchmark measures key performance indicators such as rendering duration, average FPS, and memory usage during the streaming process.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive performance benchmark for streaming Markdown rendering using Playwright, which is a valuable addition for evaluating and comparing different rendering libraries. The overall implementation is solid. My review focuses on improving code quality, maintainability, and the robustness of the testing setup. I've included suggestions for using proper TypeScript types, avoiding hardcoded values, ensuring test failures are correctly reported, and optimizing component rendering logic within the benchmark.

};
});

await page.context().tracing.stop({ path: `test-results/trace-xmarkdown.zip` });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The trace file path is hardcoded. This will cause the trace file to be overwritten by each test run, losing valuable debugging information for all but the last test. The path should be unique for each renderer being tested.

Suggested change
await page.context().tracing.stop({ path: `test-results/trace-xmarkdown.zip` });
await page.context().tracing.stop({ path: `test-results/trace-${name}.zip` });

Comment on lines 149 to 164
try {
const result = await measure({ name: rendererName, page, mount, browserName });
results.push(result);
} catch (error) {
console.error(`Error in ${rendererName}-Performance:`, error);
results.push({
name: rendererName,
duration: 0,
avgFPS: 0,
minFPS: 0,
maxFPS: 0,
maxMemory: 0,
avgMemory: 0,
totalFrames: 0,
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The try...catch block prevents a single failing benchmark from halting the entire test suite, which is good. However, by catching the error without re-throwing it, a failing test will be reported as 'passed' by the test runner. This is misleading and can hide real problems in the benchmark. To ensure failing tests are correctly reported, you should re-throw the error after handling it.

      try {
        const result = await measure({ name: rendererName, page, mount, browserName });
        results.push(result);
      } catch (error) {
        console.error(`Error in ${rendererName}-Performance:`, error);
        results.push({
          name: rendererName,
          duration: 0,
          avgFPS: 0,
          minFPS: 0,
          maxFPS: 0,
          maxMemory: 0,
          avgMemory: 0,
          totalFrames: 0,
        });
        throw error;
      }

Comment on lines 17 to 24
const MarkdownItRenderer: FC<MarkdownRendererProps> = (props) => {
const md = new MarkdownIt();

return (
// biome-ignore lint/security/noDangerouslySetInnerHtml: benchmark only
<div dangerouslySetInnerHTML={{ __html: md.render(props.md) }} />
);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The MarkdownIt instance is created on every render of the MarkdownItRenderer component. This is inefficient and might not accurately reflect a real-world usage scenario where the instance would be initialized once and reused. This could also skew the benchmark results by including the instantiation time in every render measurement.

To fix this, you should instantiate MarkdownIt outside the component, so it's only created once per module.

const md = new MarkdownIt();

const MarkdownItRenderer: FC<MarkdownRendererProps> = (props) => {
  return (
    // biome-ignore lint/security/noDangerouslySetInnerHtml: benchmark only
    <div dangerouslySetInnerHTML={{ __html: md.render(props.md) }} />
  );
};

Comment on lines 8 to 10
"test:all": "playwright test -c playwright-ct.config.ts",
"setup": "node scripts/setup.js",
"test-ct": "playwright test -c playwright-ct.config.ts"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The npm scripts test:all and test-ct are identical. This redundancy can be confusing. It's better to have a single, clearly named script for a given action. Since you are using Playwright Component Testing, test-ct is more descriptive.

    "setup": "node scripts/setup.js",
    "test-ct": "playwright test -c playwright-ct.config.ts"

@@ -0,0 +1,183 @@
import { test } from '@playwright/experimental-ct-react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To enable proper typing for Playwright fixtures like page and mount, you should also import Page and MountResult.

Suggested change
import { test } from '@playwright/experimental-ct-react';
import { test, Page, MountResult } from '@playwright/experimental-ct-react';

Comment on lines 46 to 48
default: {
return <div>{md}</div>;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The default case in the getRenderer switch statement currently renders the raw markdown text. This can silently hide errors if an unexpected renderer name is ever passed. It's safer to throw an error to fail fast and make the problem immediately obvious.

Suggested change
default: {
return <div>{md}</div>;
}
default: {
throw new Error(`Unknown renderer: ${name}`);
}

Comment on lines 57 to 62
}: {
name: string;
page: any;
mount: any;
browserName: string;
}): Promise<BenchmarkResult> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using any for page and mount parameters defeats the purpose of TypeScript. Use the specific types from Playwright for better type safety and code clarity. You'll need to import Page and MountResult as suggested in a separate comment.

Suggested change
}: {
name: string;
page: any;
mount: any;
browserName: string;
}): Promise<BenchmarkResult> {
}: {
name: string;
page: Page;
mount: (component: React.ReactElement) => Promise<MountResult>;
browserName: string;
}): Promise<BenchmarkResult> {


await page.context().tracing.start({
screenshots: true,
title: `XMarkdown_Stream_Perf_${browserName}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The trace title is not unique per renderer. When running multiple benchmark tests, this can make it harder to distinguish between traces. Including the renderer name in the title will make each trace uniquely identifiable.

Suggested change
title: `XMarkdown_Stream_Perf_${browserName}`,
title: `XMarkdown_Stream_Perf_${name}_${browserName}`,


const component = await mount(<Empty />);

const updateInterval = 50;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This file uses several 'magic numbers' for configuration, such as 50 for the update interval, 100 for the chunk size (line 98), and 1 and 120 for FPS filtering (line 116). It's a good practice to extract these into named constants at the top of the file. This improves readability and makes the benchmark easier to configure.

For example:

const UPDATE_INTERVAL = 50;
const CHUNK_SIZE = 100;
const MIN_VALID_FPS = 1;
const MAX_VALID_FPS = 120;

@codecov
Copy link

codecov bot commented Nov 10, 2025

Bundle Report

Changes will increase total bundle size by 300.1kB (169.65%) ⬆️⚠️, exceeding the configured threshold of 5%.

Bundle name Size Change
x-markdown-array-push 477.0kB 300.1kB (169.65%) ⬆️⚠️

Affected Assets, Files, and Routes:

view changes for bundle: x-markdown-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
x-markdown.js (New) 474.25kB 474.25kB 100.0% 🚀
x-markdown.css (New) 2.74kB 2.74kB 100.0% 🚀
x-markdown.min.js (Deleted) -174.15kB 0 bytes -100.0% 🗑️
x-markdown.min.css (Deleted) -2.75kB 0 bytes -100.0% 🗑️

@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2025

size-limit report 📦

Path Size
packages/x/dist/antdx.min.js 68.97 KB
packages/x-sdk/dist/x-sdk.min.js 7.32 KB
packages/x-markdown/dist/x-markdown.min.js 50.66 KB
packages/x-markdown/dist/plugins/code-high-light.min.js 280.4 KB
packages/x-markdown/dist/plugins/latex.min.js 61.95 KB
packages/x-markdown/dist/plugins/mermaid.min.js 852.75 KB

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 14, 2025

Deploying ant-design-x with  Cloudflare Pages  Cloudflare Pages

Latest commit: d95896e
Status: ✅  Deploy successful!
Preview URL: https://aababc3c.ant-design-x.pages.dev
Branch Preview URL: https://feature-markdown-benchmark.ant-design-x.pages.dev

View logs

@codecov
Copy link

codecov bot commented Nov 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.06%. Comparing base (63843da) to head (d95896e).
⚠️ Report is 1 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #1314   +/-   ##
=======================================
  Coverage   94.06%   94.06%           
=======================================
  Files         144      144           
  Lines        3708     3708           
  Branches     1028     1042   +14     
=======================================
  Hits         3488     3488           
  Misses        218      218           
  Partials        2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants