Skip to content

Commit 60ea2e5

Browse files
[charts] Benchmark charts using a real browser
1 parent 9d31fcb commit 60ea2e5

22 files changed

+887
-158
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Update Charts Benchmark Baseline
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
- 'next'
8+
paths:
9+
- 'packages/x-charts*/**'
10+
- 'test/performance-charts/**'
11+
12+
jobs:
13+
performance-test:
14+
name: Update Charts Benchmark Baseline
15+
runs-on: ubuntu-latest
16+
permissions:
17+
pull-requests: write
18+
issues: write
19+
contents: read
20+
21+
steps:
22+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
23+
- uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
24+
with:
25+
run_install: false
26+
- name: Use Node.js 22.x
27+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
28+
with:
29+
node-version: 22
30+
cache: 'pnpm' # https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#caching-packages-dependencies
31+
- run: pnpm install --frozen-lockfile
32+
- run: pnpm exec playwright install
33+
- run: pnpm --filter "@mui/x-charts-premium..." build
34+
35+
- name: Run performance tests
36+
run: pnpm --filter @mui-x-internal/performance-charts test:performance:ci
37+
- run: jq '.commit = "${{ github.sha }}"' test/performance-charts/results.json > test/performance-charts/baseline-results.json
38+
39+
- name: Upload results
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: charts-benchmarks-results-${{ github.ref_name }}.json
43+
path: ./test/performance-charts/baseline-results.json
44+
if-no-files-found: error
Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
name: Benchmarks
1+
name: Performance Test
22

33
on:
4-
push:
5-
branches:
6-
- 'master'
7-
- 'next'
8-
paths:
9-
- 'packages/x-charts*/**'
104
pull_request:
115
types:
126
- labeled
@@ -15,14 +9,15 @@ on:
159
- reopened
1610
branches:
1711
- 'master'
18-
- 'next'
19-
20-
permissions: {}
2112

2213
jobs:
23-
benchmarks:
24-
name: Benchmarks Charts
14+
performance-test:
15+
name: Benchmark Charts
2516
runs-on: ubuntu-latest
17+
permissions:
18+
pull-requests: write
19+
issues: write
20+
contents: read
2621
# L1: Run the benchmarks for pushes to the master or next branch and if the changes are in the charts package based on on.push.paths
2722
# L2: Run the benchmarks if we add the label 'scope: charts' to the pull request
2823
# L3: Run the benchmarks for pull requests with the label 'scope: charts'
@@ -33,6 +28,7 @@ jobs:
3328
(github.event_name == 'pull_request' && github.event.action == 'labeled' && github.event.label.name == 'scope: charts') ||
3429
(github.event_name == 'pull_request' && github.event.action != 'labeled' && contains(github.event.pull_request.labels.*.name, 'scope: charts'))
3530
}}
31+
3632
steps:
3733
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3834
- uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
@@ -44,10 +40,30 @@ jobs:
4440
node-version: 22
4541
cache: 'pnpm' # https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#caching-packages-dependencies
4642
- run: pnpm install --frozen-lockfile
43+
- run: pnpm exec playwright install
4744
# Ensure we are running on the prod version of our libs
4845
- run: pnpm --filter "@mui/x-charts-premium..." build
49-
- name: Run benchmarks
50-
uses: CodSpeedHQ/action@c28fe9fbe7d57a3da1b7834ae3761c1d8217612d
46+
47+
- name: Download baseline results, if available
48+
run: |
49+
echo "Downloading baseline results from branch '${{ github.base_ref }}' for performance tests"
50+
gh run download --name "charts-benchmarks-results-${{ github.base_ref }}.json" || true
51+
[[ -e ./baseline-results.json ]] && echo "Found baseline, comparing results..." || echo "No baseline results found, skipping comparison"
52+
mv ./baseline-results.json ./test/performance-charts/baseline-results.json || true
53+
54+
env:
55+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
57+
- name: Run performance tests
58+
run: pnpm --filter @mui-x-internal/performance-charts test:performance:ci
59+
60+
- name: Compare performance results
61+
uses: actions/github-script@v7
62+
env:
63+
BASELINE_PATH: ./test/performance-charts/baseline-results.json
64+
COMPARE_PATH: ./test/performance-charts/results.json
65+
THRESHOLD: 0.1
5166
with:
52-
run: pnpm --filter @mui-x-internal/performance-charts test:performance
53-
token: ${{ secrets.CODSPEED_TOKEN }}
67+
script: |
68+
const { default: ciBenchmark } = await import('${{ github.workspace }}/test/performance-charts/scripts/ci-benchmark.js');
69+
await ciBenchmark({github, context, core});

patches/@vitest__browser.patch

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
diff --git a/dist/client/__vitest_browser__/tester-BYDMHqQ9.js b/dist/client/__vitest_browser__/tester-BYDMHqQ9.js
2+
index 9916c1f32e9af801b6d425d1ec785f23e830a236..c748ab51bb7c3f236334f4994bab6c0d76902d12 100644
3+
--- a/dist/client/__vitest_browser__/tester-BYDMHqQ9.js
4+
+++ b/dist/client/__vitest_browser__/tester-BYDMHqQ9.js
5+
@@ -11,6 +11,27 @@ const assetsURL = function(dep) {
6+
return "/" + dep;
7+
};
8+
const seen = {};
9+
+async function getTestRunnerConstructor(
10+
+ config,
11+
+ executor,
12+
+){
13+
+ if (!config.runner) {
14+
+ const { VitestTestRunner, NodeBenchmarkRunner }
15+
+ = await executor.executeFile(runnersFile)
16+
+ return (
17+
+ config.mode === 'test' ? VitestTestRunner : NodeBenchmarkRunner
18+
+ );
19+
+ }
20+
+ const mod = await executor.executeId(config.runner)
21+
+ if (!mod.default && typeof mod.default !== 'function') {
22+
+ throw new Error(
23+
+ `Runner must export a default function, but got ${typeof mod.default} imported from ${
24+
+ config.runner
25+
+ }`,
26+
+ )
27+
+ }
28+
+ return mod.default;
29+
+}
30+
const __vitePreload = function preload(baseModule, deps, importerUrl) {
31+
let promise = Promise.resolve();
32+
if (deps && deps.length > 0) {
33+
@@ -1660,7 +1681,7 @@ async function initiateRunner(state, mocker, config) {
34+
if (cachedRunner) {
35+
return cachedRunner;
36+
}
37+
- const runnerClass = config.mode === "test" ? VitestTestRunner : NodeBenchmarkRunner;
38+
+ const runnerClass = await getTestRunnerConstructor(config, executor);
39+
const BrowserRunner = createBrowserRunner(runnerClass, mocker, state, {
40+
takeCoverage: () => takeCoverageInsideWorker(config.coverage, executor)
41+
});

pnpm-lock.yaml

Lines changed: 45 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,6 @@ onlyBuiltDependencies:
9292
- nx
9393
- sharp
9494
- unrs-resolver
95+
96+
patchedDependencies:
97+
'@vitest/browser': patches/@vitest__browser.patch

0 commit comments

Comments
 (0)