-
Notifications
You must be signed in to change notification settings - Fork 46.8k
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
Add React benchmarking infrastructure #9465
Conversation
…o add_benchmarking_infra
@spicyj can you do one more pass on this review before I merge please? |
Sure. Anything in particular you'd like me to focus on? |
@spicyj I added a README.md and commented on the commands possible along with some tweaks to the benchmarks. I feel that this is in good shape to merge now – the variance we're seeing is as good as I feel I can get it at this point. If you can see anything I might have missed, please let me know. |
(I’m going to look at this now too.) |
.eslintignore
Outdated
@@ -13,6 +13,7 @@ fixtures/ | |||
# Ignore built files. | |||
build/ | |||
coverage/ | |||
scripts/bench/bench-*.js | |||
scripts/bench/benchmarks/**/*.js | |||
scripts/old-bench/bench-*.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this can be removed.
.flowconfig
Outdated
@@ -4,6 +4,8 @@ | |||
<PROJECT_ROOT>/build/.* | |||
<PROJECT_ROOT>/scripts/.* | |||
<PROJECT_ROOT>/.*/node_modules/y18n/.* | |||
<PROJECT_ROOT>/node_modules/chrome-devtools-frontend/.* | |||
<PROJECT_ROOT>/node_modules/devtools-timeline-model/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this end with .*
?
circle.yml
Outdated
@@ -2,7 +2,7 @@ | |||
machine: | |||
timezone: America/Los_Angeles | |||
node: | |||
version: 6 | |||
version: 7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we change this? We're not running benches on CI yet, are we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node 7 should be faster than Node 6. Not a big deal though.
@@ -0,0 +1,7 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid checking in built copies of React? People will attempt to edit or download them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point
scripts/bench/README.md
Outdated
|
||
You'll need two folders to compare, each of them containing `react.min.js` and `react-dom-server.min.js`. You can run `npm run build` at the repo root to get a `build` folder with these files. | ||
```bash | ||
# will comapre local repo vs remote merge base repo (default run) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: compare (here and below).
What does "(default run)" mean?
package.json
Outdated
@@ -60,16 +60,22 @@ | |||
"git-branch": "^0.3.0", | |||
"glob": "^6.0.4", | |||
"glob-stream": "^6.1.0", | |||
"google-closure-compiler-js": "^20170409.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it used currently, or was it added for future experimentation? If not used let's remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed, was used for static-www build
async function runRemoteBenchmarks(showResults) { | ||
console.log( | ||
chalk.white.bold('Running benchmarks for ') | ||
+ chalk.yellow.bold('Remote (Merge Base)') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would be helpful to have a commit hash here?
Or maybe even print a GitHub link to commit below.
Can we avoid the |
@gaearon I changed the path last week to be On a side note: all the feedback above has been addressed now! |
Ah, I got it now. I just had it from previous version. |
scripts/bench/README.md
Outdated
|
||
For example, if you want to compare a stable verion against master, you can create folders called `build-stable` and `build-master` and use the benchmark scripts like this: | ||
# will comapre local repo vs remote merge base repo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: type here too
scripts/bench/README.md
Outdated
## Running one | ||
One thing you can do with them is benchmark initial render time for a realistic hierarchy: | ||
# runs benchmarks with Chrome in headless mode | ||
yarn bench -- --headless |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it better? Should it be the default? When would you want to use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, the results weren't as effective by default. Headless runs everything much faster (it seems) so it was hard to get good feedback and it seems like it's still a new feature. We can revisit adding this by default in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do they recommend to use it for perf testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had no official say-so for perf testing. I'll chase someone to get some feedback on using it before enabling it by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meaning the variance was higher?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variance was all over the place in some runs and better in others. It was too unreliable and no one could tell me as why this is currently the case with headless mode.
scripts/bench/README.md
Outdated
|
||
You can name folders any way you like, this was just an example. | ||
# same as "yarn build" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably "yarn bench"?
scripts/bench/README.md
Outdated
$ ./measure.py build-stable stable.txt build-master master.txt | ||
$ ./analyze.py stable.txt master.txt | ||
``` | ||
# will only build and run local repo against benchmarks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't fully understand what these two commands do. (--local
and --remote
)
If I run --local
will it not benchmark remote at all? Or will it just skip the build for remote?
If it doesn't run remote, how would I interpret the benchmark? Does it mean I'll only get absolute numbers as there's nothing to compare to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's only for absolute values
scripts/bench/server.js
Outdated
const mime = require('mime'); | ||
|
||
const options = { | ||
// key: readFileSync(join(__dirname, 'certs', 'facebook-www.key')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we delete this?
scripts/bench/stats.js
Outdated
} | ||
|
||
function addBundleSizeComparions(table, localResults, remoteMasterResults) { | ||
const bunldesRowHeader = [chalk.white.bold('Bundles')]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: bunldes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran this a few times, and it behaves mostly as I would expect. Seems like it's important not to switch the active process while the bench is running (e.g. brining Chromium into foreground during one run but not the other significantly skews it).
I did not review the statistical stuff as I trust @spicyj with this. I did not review in detail how you call Lighthouse since you have way more knowledge about this.
I'm approving but please make the instructions for different options clearer. As in "when would I want to run this".
Also please remove the remaining built react
files from the repo (there's still a few being added in this PR).
One additional nit is I'd like this to be tweaked:
Note how in this example one of them improved and the other regressed, but it's not clear what the cumulative effect is. It would help to have a Load React + ReactDOM (Total). |
This is currently a WIP and is not yet complete.
The aim of this PR is to give us better tracking of performance and bundle sizes as we make changes to the React codebase.
To do this, new infrastructure is needed to validate our code changes against pre-defined benchmarks. We can do this using Google's Lighthouse tool, performance markers in the benchmarks, an automated build process. For now the benchmarking script does a build and benchmark run comparing the
local
React repo and aremote merge base
React repo.The end goal is to have this process run on a CI pipeline which can provide us feedback in builds/PRs so we have constant feedback in regards to performance improvements and regressions.
To test how this works, run:
yarn bench
From the branch on this PR. It should take a few minutes to run and report back the performance metrics of
local
andremote merge base
.There are still things that need to be finished:
yarn bench
is runfunctional-components
benchmark