Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix benchmark runner #11749

Merged
merged 1 commit into from
Dec 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions scripts/bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,38 @@

In most cases, the only two commands you might want to use are:

- `yarn bench`
- `yarn build -- --type=UMD_PROD && yarn bench -- --skip-build`
- `yarn start`
- `yarn build core,dom-client --type=UMD_PROD && yarn start --skip-build`

The first command will run benchmarks with all the default settings. A local and remote build will occcur on all bundles, both local and remote repos will be run against all benchmarks.
The first command will run benchmarks with all the default settings. A local and remote build will occur on React and ReactDOM UMD bundles, both local and remote repos will be run against all benchmarks.

The second command will run all benchmarks but skip the build process. This is useful for when doing local performance tweaking and the remote repo has already had its bundles built. Both local and remote repos will be run against all benchmarks with this command too.

The other commands are as follows:

```bash
# will compare local repo vs remote merge base repo
yarn bench
yarn start

# will compare local repo vs remote merge base repo
# this can significantly improve bench times due to no build
yarn bench -- --skip-build
yarn start --skip-build

# will only build and run local repo against benchmarks (no remote values will be shown)
yarn bench -- --local
yarn start --local

# will only build and run remote merge base repo against benchmarks (no local values will be shown)
yarn bench -- --remote
yarn start --remote

# will only build and run remote master repo against benchmarks
yarn bench -- --remote=master
yarn start --remote=master

# same as "yarn bench"
yarn bench -- --remote --local
# same as "yarn start"
yarn start --remote --local

# runs benchmarks with Chrome in headless mode
yarn bench -- --headless
yarn start --headless

# runs only specific string matching benchmarks
yarn bench -- --benchmark=hacker
yarn start --benchmark=hacker
```
22 changes: 6 additions & 16 deletions scripts/bench/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ function getDefaultReactPath() {
return join(__dirname, 'remote-repo');
}

async function buldAllBundles(reactPath = getDefaultReactPath()) {
// build the react FB bundles in the build
await executeCommand(`cd ${reactPath} && yarn && yarn build`);
}

async function buildBenchmark(reactPath = getDefaultReactPath(), benchmark) {
// get the build.js from the benchmark directory and execute it
await require(join(__dirname, 'benchmarks', benchmark, 'build.js'))(
Expand All @@ -55,10 +50,6 @@ async function buildBenchmark(reactPath = getDefaultReactPath(), benchmark) {
);
}

function getBundleResults(reactPath = getDefaultReactPath()) {
return require(join(reactPath, 'scripts', 'rollup', 'results.json'));
}

async function getMergeBaseFromLocalGitRepo(localRepo) {
const repo = await Git.Repository.open(localRepo);
return await Git.Merge.base(
Expand Down Expand Up @@ -106,17 +97,16 @@ async function buildBenchmarkBundlesFromGitRepo(
// then we checkout the merge base
await Git.Checkout.tree(repo, commit);
}
await buildAllBundles();
await buildReactBundles();
}
return getBundleResults();
}

async function buildAllBundles(reactPath, skipBuild) {
async function buildReactBundles(reactPath = getDefaultReactPath(), skipBuild) {
if (!skipBuild) {
// build all bundles so we can get all stats and use bundles for benchmarks
await buldAllBundles(reactPath);
await executeCommand(
`cd ${reactPath} && yarn && yarn build core,dom-client --type=UMD_PROD`
);
}
return getBundleResults(reactPath);
}

// if run directly via CLI
Expand All @@ -125,7 +115,7 @@ if (require.main === module) {
}

module.exports = {
buildAllBundles,
buildReactBundles,
buildBenchmark,
buildBenchmarkBundlesFromGitRepo,
getMergeBaseFromLocalGitRepo,
Expand Down
10 changes: 3 additions & 7 deletions scripts/bench/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {readdirSync, statSync} = require('fs');
const {join} = require('path');
const runBenchmark = require('./benchmark');
const {
buildAllBundles,
buildReactBundles,
buildBenchmark,
buildBenchmarkBundlesFromGitRepo,
getMergeBaseFromLocalGitRepo,
Expand Down Expand Up @@ -72,10 +72,8 @@ async function benchmarkRemoteMaster() {
chalk.gray(`- Merge base commit ${chalk.white(commit.tostrS())}`)
);
}
await buildBenchmarkBundlesFromGitRepo(commit, skipBuild);
return {
// we build the bundles from the React repo
bundles: await buildBenchmarkBundlesFromGitRepo(commit, skipBuild),
// we use these bundles to run the benchmarks
benchmarks: await runBenchmarks(),
};
}
Expand All @@ -84,10 +82,8 @@ async function benchmarkRemoteMaster() {
// of the local react repo
async function benchmarkLocal(reactPath) {
console.log(chalk.gray(`- Building React bundles...`));
await buildReactBundles(reactPath, skipBuild);
return {
// we build the bundles from the React repo
bundles: await buildAllBundles(reactPath, skipBuild),
// we use these bundles to run the benchmarks
benchmarks: await runBenchmarks(reactPath),
};
}
Expand Down
49 changes: 0 additions & 49 deletions scripts/bench/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,52 +93,6 @@ function addBenchmarkResults(table, localResults, remoteMasterResults) {
});
}

function addBundleSizeComparsions(table, localResults, remoteMasterResults) {
const bundlesRowHeader = [chalk.white.bold('Bundles')];
if (remoteMasterResults) {
bundlesRowHeader.push(chalk.white.bold('Size'));
}
if (localResults) {
bundlesRowHeader.push(chalk.white.bold('Size'));
}
if (localResults && remoteMasterResults) {
bundlesRowHeader.push(chalk.white.bold('Diff'));
}
table.push(bundlesRowHeader);

const bundles = Object.keys(
(localResults && localResults.bundles.bundleSizes) ||
(remoteMasterResults && remoteMasterResults.bundles.bundleSizes)
);
bundles.forEach(bundle => {
const row = [chalk.gray(bundle)];
let remoteSize = 0;
if (remoteMasterResults) {
const remoteBundle = (remoteSize =
remoteMasterResults.bundles.bundleSizes[bundle]);

if (remoteBundle) {
remoteSize = remoteSize.size;
}
row.push(chalk.white(remoteSize + ' kb'));
}
let localSize = 0;
if (localResults) {
const localBundle = localResults.bundles.bundleSizes[bundle];

if (localBundle) {
localSize = localBundle.size;
}
localSize = localResults.bundles.bundleSizes[bundle].size;
row.push(chalk.white(localSize + ' kb'));
}
if (localResults && remoteMasterResults) {
row.push(percentChange(remoteSize, localSize, 0, 0));
}
table.push(row);
});
}

function printResults(localResults, remoteMasterResults) {
const head = [''];
if (remoteMasterResults) {
Expand All @@ -151,10 +105,7 @@ function printResults(localResults, remoteMasterResults) {
head.push('');
}
const table = new Table({head});

addBundleSizeComparsions(table, localResults, remoteMasterResults);
addBenchmarkResults(table, localResults, remoteMasterResults);

console.log(table.toString());
}

Expand Down