Skip to content

Commit 6bc3c0a

Browse files
Add loading time check on CI (#2163)
# Summary - This PR started as an attempt to make CI use the `@size-limit/time` plugin to measure the execution time of each client bundle and ensure it doesn't exceed the base branch execution time by more than 20%. - Later, found that the `@size-limit/time` plugin is not good at all at detecting that because of the runtime noise on CI. - So, CI will only look for the `download time` of chunks at the browser for now, until finding another tool that run the code multiple time on CI and get average execution time to get rid of runtime noise. - However, the following changes are made: - The feature of measring the execution time and comparing it to the base branch is already added to the `bin/compare-bundle-sizes` script, so if you can run it locally with a noise mitigated environment you can do that by changing the `running` values at `.size-limit.json` file to `true`. - Removed the `compare` command from the `scripts/bundle-size.mjs` script as it's not needed and used the default comparison behavior at the `size-limit` package.
1 parent 01bc7b9 commit 6bc3c0a

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

.github/workflows/bundle-size.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
echo "skip=false" >> $GITHUB_OUTPUT
3434
fi
3535
36-
size:
36+
check-bundle-size:
3737
needs: check-skip
3838
if: needs.check-skip.outputs.skip != 'true'
3939
runs-on: ubuntu-22.04
@@ -108,6 +108,9 @@ jobs:
108108
- name: Copy .size-limit.json file with limits to tmp directory
109109
run: cp .size-limit.json /tmp/.size-limit-with-limits.json
110110

111+
- name: Copy .size-limit.json file with limits to tmp directory
112+
run: cp .size-limit.json /tmp/.size-limit-with-limits.json
113+
111114
# 4. Run the action with dynamic limits
112115
- name: Check bundle size
113116
uses: andresz1/size-limit-action@v1

.size-limit.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,55 @@
44
"path": "packages/react-on-rails/lib/ReactOnRails.client.js",
55
"import": "ReactOnRails",
66
"gzip": true,
7-
"running": true
7+
"running": false
88
},
99
{
1010
"name": "react-on-rails/client bundled (brotli)",
1111
"path": "packages/react-on-rails/lib/ReactOnRails.client.js",
1212
"import": "ReactOnRails",
1313
"brotli": true,
14-
"running": true
14+
"running": false
1515
},
1616
{
1717
"name": "react-on-rails-pro/client bundled (gzip)",
1818
"path": "packages/react-on-rails-pro/lib/ReactOnRails.client.js",
1919
"import": "ReactOnRails",
2020
"gzip": true,
21-
"running": true
21+
"running": false
2222
},
2323
{
2424
"name": "react-on-rails-pro/client bundled (brotli)",
2525
"path": "packages/react-on-rails-pro/lib/ReactOnRails.client.js",
2626
"import": "ReactOnRails",
2727
"brotli": true,
28-
"running": true
28+
"running": false
2929
},
3030
{
3131
"name": "registerServerComponent/client bundled (gzip)",
3232
"path": "packages/react-on-rails-pro/lib/registerServerComponent/client.js",
3333
"import": "registerServerComponent",
3434
"gzip": true,
35-
"running": true
35+
"running": false
3636
},
3737
{
3838
"name": "registerServerComponent/client bundled (brotli)",
3939
"path": "packages/react-on-rails-pro/lib/registerServerComponent/client.js",
4040
"import": "registerServerComponent",
4141
"brotli": true,
42-
"running": true
42+
"running": false
4343
},
4444
{
4545
"name": "wrapServerComponentRenderer/client bundled (gzip)",
4646
"path": "packages/react-on-rails-pro/lib/wrapServerComponentRenderer/client.js",
4747
"import": "wrapServerComponentRenderer",
4848
"gzip": true,
49-
"running": true
49+
"running": false
5050
},
5151
{
5252
"name": "wrapServerComponentRenderer/client bundled (brotli)",
5353
"path": "packages/react-on-rails-pro/lib/wrapServerComponentRenderer/client.js",
5454
"import": "wrapServerComponentRenderer",
5555
"brotli": true,
56-
"running": true
56+
"running": false
5757
}
5858
]

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Changes since the last non-beta release.
2525

2626
#### Added
2727

28-
- **Total Execution Time CI Monitoring**: Added automated execution time tracking to CI using size-limit. Compares PR client import execution times against the base branch and fails if any import increases by more than 20%. [PR 2160](https://github.com/shakacode/react_on_rails/pull/2160) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
28+
- **Download Time CI Monitoring**: Added automated download time tracking to CI using size-limit. Compares PR client import download times against the base branch and fails if any import increases by more than 10%. And added ability to compare the total execution time (download + running time) to the `bin/compare-bundle-sizes` script. [PR 2160](https://github.com/shakacode/react_on_rails/pull/2160) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
2929

3030
- **Bundle Size CI Monitoring**: Added automated bundle size tracking to CI using size-limit. Compares PR bundle sizes against the base branch and fails if any package increases by more than 0.5KB. Includes local comparison tool (`bin/compare-bundle-sizes`) and bypass mechanism (`bin/skip-bundle-size-check`) for intentional size increases. [PR 2149](https://github.com/shakacode/react_on_rails/pull/2149) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
3131

packages/react-on-rails-pro/temp.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts/bundle-size.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import fs from 'fs';
1818
// Intentionally strict to catch any bundle size changes early.
1919
// For intentional size increases, use bin/skip-bundle-size-check to bypass the CI check.
2020
const DEFAULT_THRESHOLD = 512;
21-
// 20% is a big ration, but the current approach is not accurate enough to detect rations less than that
21+
// 10% is a big ratio, but the current approach is not accurate enough to detect rations less than that
2222
// Later, we will implement performance tests that will use more accurate mechanisms and can detect smaller performance regressions
23-
const DEFAULT_TIME_PERCENTAGE_THRESHOLD = 0.2;
23+
const DEFAULT_TIME_PERCENTAGE_THRESHOLD = 0.1;
2424
const DEFAULT_CONFIG = '.size-limit.json';
2525

2626
// ANSI color codes
@@ -102,11 +102,11 @@ function createLimitEntry(entry, baseEntry, threshold, timePercentageThreshold)
102102
console.log(` base size: ${formatSize(baseEntry.size)}`);
103103
console.log(` limit: ${formatSize(limit)}\n`);
104104
const sizeLimitEntry = { ...entry, limit: `${limit} B` };
105-
if (!sizeLimitEntry.running) {
105+
if (!baseEntry.running && !baseEntry.loading) {
106106
return sizeLimitEntry;
107107
}
108108

109-
const { loading, running } = baseEntry;
109+
const { loading = 0, running = 0 } = baseEntry;
110110
const loadingMs = loading * 1000;
111111
const runningMs = running * 1000;
112112
console.log(` base loading time: ${formatTime(loadingMs)}`);

0 commit comments

Comments
 (0)