Skip to content

Commit

Permalink
setup-bench script
Browse files Browse the repository at this point in the history
setup-bench script

+

add alias

+

+

+

+

+

lintfix

+
  • Loading branch information
lifeart committed Dec 22, 2023
1 parent 040ebba commit 32411a6
Show file tree
Hide file tree
Showing 7 changed files with 2,965 additions and 204 deletions.
Binary file added .DS_Store
Binary file not shown.
57 changes: 5 additions & 52 deletions .github/workflows/perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,25 @@ on:
branches: [master]

env:
TURBO_API: http://127.0.0.1:9080
TURBO_TOKEN: this-is-not-a-secret
TURBO_TEAM: myself
CONTROL_DIR: '/tmp/glimmer-vm-control/'
EXPERIMENT_BRANCH_NAME: ${{ github.sha }}
CONTROL_BRANCH_NAME: 'main'
FIDELITY: 100

jobs:
master-krausest-comparison:
name: Glimmer Krausest Benchmark
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: 'Setup local TurboRepo server'
if: ${{ inputs.repo-token }}
uses: felixmosh/turborepo-gh-artifacts@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: wyvox/action-setup-pnpm@v3
with:
node-version: '20.1.0'

- name: Build Experiment
run: |
git checkout ${{ github.sha }}
pnpm install
pnpm build
- name: Build Control
run: |
rm -rf ${{ env.CONTROL_DIR }}
mkdir -p ${{ env.CONTROL_DIR }}
cd ${{ env.CONTROL_DIR }}
git clone ${{ github.workspace }} ${{ env.CONTROL_DIR }}
cd ${{ env.CONTROL_DIR }}
git checkout ${{ github.event.pull_request.base.sha }}
pnpm install
pnpm build
- name: Run Analysis
timeout-minutes: 10
uses: tracerbench/tracerbench-compare-action@master
with:
build-control: false
build-experiment: false
pkg-manager: pnpm
use-pnpm: true
sample-timeout: 10
runtime-stats: true
control-dist: ${{ env.CONTROL_DIR }}/benchmark/benchmarks/krausest
experiment-dist: ${{ github.workspace }}/benchmark/benchmarks/krausest
# temporary, because the control branch is behind
# cd ${{ env.CONTROL_DIR }}/benchmark/benchmarks/krausest && pnpm run start --port 5000
control-serve-command: |
cd ${{ github.workspace }}/benchmark/benchmarks/krausest && pnpm vite --port 5000 &
experiment-serve-command: |
cd ${{ github.workspace }}/benchmark/benchmarks/krausest && pnpm vite --port 6000 &
control-url: http://localhost:5000
experiment-url: http://localhost:6000
debug: true
regression-threshold: 25
fidelity: low
markers: 'glimmer-render-1000-rows,glimmer-render-1000-rows-finished'
clean-after-analyze: false
- name: RUN
run: pnpm run benchmark:setup

- name: Upload Tracerbench Artifacts
if: failure() || success()
Expand Down
22 changes: 22 additions & 0 deletions benchmark/benchmarks/krausest/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,26 @@ export default async function render(element, isInteractive) {
performance.mark('glimmer-render-1000-rows');
await benchmark.render('Application', args, element, isInteractive);
performance.mark('glimmer-render-1000-rows-finished');
enforcePaintEvent();
}

function enforcePaintEvent() {
const docElem = document.documentElement;
const refNode = docElem.firstElementChild || docElem.firstChild;
const fakeBody = document.createElement('body');
const div = document.createElement('div');

div.id = 'mq-test-1';
div.style.cssText = 'position:absolute;top:-100em';
fakeBody.style.background = 'none';
fakeBody.appendChild(div);
div.innerHTML = '&shy;<style> #mq-test-1 { width: 42px; }</style>';
docElem.insertBefore(fakeBody, refNode);

try {
return div.offsetWidth === 42;
} finally {
fakeBody.removeChild(div);
docElem.removeChild(fakeBody);
}
}
29 changes: 28 additions & 1 deletion benchmark/benchmarks/krausest/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,45 @@ import fs from 'node:fs';

import { precompile } from '@glimmer/compiler';
import { defineConfig, type Plugin } from 'vite';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const self = import.meta.url;

const packagesPath = path.resolve(path.dirname(fileURLToPath(self)), '..', '..', './../packages');

const packagePath = (name: string) => {
return path.join(packagesPath, name, 'dist/prod/index.js');
};

export default defineConfig({
plugins: [benchmark()],
resolve: {
conditions: ['control'],
alias: {
'@glimmer-workspace/benchmark-env': '@glimmer-workspace/benchmark-env/index.ts',
'@glimmer/debug': packagePath('@glimmer/debug'),
},
},
});

function benchmark(): Plugin {
return {
enforce: 'pre',
name: '@glimmer/benchmark',
resolveId(id) {
if (id === '@glimmer/env') {
return '\0@glimmer/env';
} else if (id === '@glimmer/local-debug-flags') {
return '\0@glimmer/local-debug-flags';
}
},
load(id) {
if (id === '\0@glimmer/env') {
return `export const DEBUG = false;`;
} else if (id === '\0@glimmer/local-debug-flags') {
return `export const LOCAL_SHOULD_LOG = false;`;
}
console.log(id);
/** @type {string | undefined} */
let result: string | undefined;
if (id.endsWith('.hbs')) {
Expand Down
107 changes: 107 additions & 0 deletions bin/setup-bench.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import 'zx/globals';
import os from 'node:os';
import { join } from 'node:path';

/*
To run proper bench setup we need to do following things:
1.) Compile control packages
2.) Compile experiment packages
3.) Use SAME benchmark source
* we should be able to tweak bench
(add more cases, and still be able to compare with control)
* we should be able to re-run bench in CI from current branch with updated perf source
*/

const experimentBranchName =
process.env['EXPERIMENT_BRANCH_NAME'] || 'attempt-to-get-perf-testing-work';
const controlBranchName = process.env['CONTROL_BRANCH_NAME'] || 'main';
const markers = process.env['MARKERS'] || 'glimmer-render-1000-rows,glimmer-render-1000-rows-finished';
const fidelity = process.env['FIDELITY'] || '20';
const throttleRate = process.env['THROTTLE'] || '4';

const tempDir = os.tmpdir();

const CONTROL_DIR = join(tempDir, 'control');
const EXPERIMENT_DIR = join(tempDir, 'experiment');

const CONTROL_BENCH_DIR = join(CONTROL_DIR, 'benchmark', 'benchmarks', 'krausest');
const EXPERIMENT_BENCH_DIR = join(EXPERIMENT_DIR, 'benchmark', 'benchmarks', 'krausest');

const pwdRaw = await $`pwd`;
const pwd = pwdRaw.toString().trim();

// we use benchmark from current commit, very useful if we need to tweak it
const benchmarkFolder = 'benchmark';

// remove node_modules from benchmark folder, maybe we could figure out better option to distribute bench source
await $`rm -rf ${join(pwd, benchmarkFolder, 'node_modules')}`;
await $`rm -rf ${join(pwd, benchmarkFolder, 'benchmarks', 'krausest', 'node_modules')}`;

await $`rm -rf ${CONTROL_DIR}`;
await $`rm -rf ${EXPERIMENT_DIR}`;
await $`mkdir ${CONTROL_DIR}`;
await $`mkdir ${EXPERIMENT_DIR}`;

const BENCHMARK_FOLDER = join(pwd, benchmarkFolder);

const rawUpstreamUrl = await $`git ls-remote --get-url upstream`;
const rawOriginUrl = await $`git ls-remote --get-url origin`;
const originUrlStr = rawOriginUrl.toString().trim();
const upstreamUrlStr = rawUpstreamUrl.toString().trim();
const CONTROL_PORT = 4020;
const EXPERIMENT_PORT = 4021;
const CONTROL_URL = `http://localhost:${CONTROL_PORT}`;
const EXPERIMENT_URL = `http://localhost:${EXPERIMENT_PORT}`;
// const MARKERS = ['glimmer-render-1000-rows', 'glimmer-render-1000-rows-finished'];

await Promise.all([
$`cd ${CONTROL_DIR} && git clone ${upstreamUrlStr} . && git checkout ${controlBranchName} && rm -rf benchmark && cp -r ${BENCHMARK_FOLDER} ./benchmark && pnpm install && pnpm build`,
$`cd ${EXPERIMENT_DIR} && git clone ${originUrlStr} . && git checkout ${experimentBranchName} && rm -rf benchmark && cp -r ${BENCHMARK_FOLDER} ./benchmark && pnpm install && pnpm build`,
]);

// create vite production build
// cd ${{ github.workspace }}/benchmark/benchmarks/krausest && pnpm vite --port 5000

// replace incorrect paths in package json

// in control
await $`cd ${CONTROL_DIR} && find ./packages -name 'package.json' -exec sed -i '' 's|"main": "index.ts",|"module": "./dist/prod/index.js","main": "./dist/prod/index.js",|g' {} \\;`;
await $`cd ${CONTROL_DIR} && find ./packages -name 'package.json' -exec sed -i '' 's|"main": "./dist/index.js",|"module": "./dist/prod/index.js","main": "./dist/prod/index.js",|g' {} \\;`;
await $`cd ${CONTROL_DIR} && find ./packages -name 'package.json' -exec sed -i '' 's|"import": "./dist/index.js"|"import": "./dist/prod/index.js"|g' {} \\;`;

// in experiment
await $`cd ${EXPERIMENT_DIR} && find ./packages -name 'package.json' -exec sed -i '' 's|"main": "index.ts",|"main": "./dist/prod/index.js","module": "./dist/prod/index.js",|g' {} \\;`;
await $`cd ${EXPERIMENT_DIR} && find ./packages -name 'package.json' -exec sed -i '' 's|"main": "./dist/index.js",|"main": "./dist/prod/index.js","module": "./dist/prod/index.js",|g' {} \\;`;
await $`cd ${EXPERIMENT_DIR} && find ./packages -name 'package.json' -exec sed -i '' 's|"import": "./dist/index.js"|"import": "./dist/prod/index.js"|g' {} \\;`;

// build control and experiment
await Promise.all([
$`cd ${CONTROL_BENCH_DIR} && pnpm vite build`,
$`cd ${EXPERIMENT_BENCH_DIR} && pnpm vite build`,
]).catch((e) => {
console.log({
upstreamUrlStr,
originUrlStr,
EXPERIMENT_DIR,
CONTROL_DIR,
});
throw e;
});

// start build assets
Promise.all([
$`cd ${CONTROL_BENCH_DIR} && pnpm vite preview --port ${CONTROL_PORT}`,
$`cd ${EXPERIMENT_BENCH_DIR} && pnpm vite preview --port ${EXPERIMENT_PORT}`,
]);

await new Promise((resolve) => {
// giving 5 seconds for the server to start
setTimeout(resolve, 5000);
});

await $`./node_modules/.bin/tracerbench compare --fidelity ${fidelity} --markers ${markers} --controlURL ${CONTROL_URL} --experimentURL ${EXPERIMENT_URL} --report --headless --cpuThrottleRate ${throttleRate}`;

process.exit(0);
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"scripts": {
"benchmark:build": "node benchmark/bin/build.js",
"benchmark:setup": "zx ./bin/setup-bench.mjs",
"benchmark": "node bin/run-tracerbench.mjs",
"benchmark:control": "node benchmark/bin/control.js",
"benchmark:experiment": "node benchmark/bin/experiment.js",
Expand Down Expand Up @@ -108,6 +109,8 @@
"eslint-plugin-unused-imports": "^3.0.0",
"esyes": "^1.0.1",
"execa": "^7.1.1",
"tracerbench": "^8.0.1",
"zx": "^7.2.3",
"fast-glob": "^3.2.12",
"glob": "^10.2.3",
"js-yaml": "^4.1.0",
Expand Down
Loading

0 comments on commit 32411a6

Please sign in to comment.