Skip to content

Commit

Permalink
Clean up benchmark setup and fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Jan 19, 2025
1 parent 5a0fa37 commit 2b8b1f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 102 deletions.
112 changes: 12 additions & 100 deletions bin/setup-bench.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { join } from 'node:path';
import type { PackageJson } from 'type-fest';
import { WORKSPACE_ROOT } from '@glimmer-workspace/repo-metadata';
import fs from 'fs-extra';
import { mkdirp } from 'mkdirp';
import { $, cd, which, within } from 'zx';
import { $, which } from 'zx';

import { buildKrausestDeps } from './bench-packages.mts';

Expand All @@ -15,8 +14,7 @@ const { ensureDirSync, writeFileSync } = fs;
const ROOT = new URL('..', import.meta.url).pathname;
$.verbose = true;

const REUSE_CONTROL = !!(process.env['REUSE_DIRS'] || process.env['REUSE_CONTROL']);
const REUSE_EXPERIMENT = !!(process.env['REUSE_DIRS'] || process.env['REUSE_EXPERIMENT']);
const REUSE_CONTROL = !!process.env['REUSE_CONTROL'];

/*
Expand Down Expand Up @@ -81,9 +79,6 @@ const EXPERIMENT_DIRS = {
src: join(WORKSPACE_ROOT, 'benchmark/benchmarks/krausest'),
};

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

const CONTROL_PORT = 4020;
const EXPERIMENT_PORT = 4021;
const CONTROL_URL = `http://localhost:${CONTROL_PORT}`;
Expand Down Expand Up @@ -120,15 +115,18 @@ console.info({

// set up control
{
await $`rm -rf ${CONTROL_DIRS.root}`;
await $`mkdir -p ${CONTROL_DIRS.bench}`;
if (!REUSE_CONTROL) {
await $`rm -rf ${CONTROL_DIRS.root}`;
await $`mkdir -p ${CONTROL_DIRS.bench}`;

// Intentionally use the `krausest` folder from the experiment in both
// control and experiment
await $`cp -r ${EXPERIMENT_DIRS.src}/* ${CONTROL_DIRS.bench}/`;

// Intentionally use the `krausest` folder from the experiment in both
// control and experiment
await $`cp -r ${EXPERIMENT_DIRS.src}/* ${CONTROL_DIRS.bench}/`;
// clone the raw git repo for the experiment
await $`git clone ${join(ROOT, '.git')} ${CONTROL_DIRS.repo}`;
}

// clone the raw git repo for the experiment
await $`git clone ${join(ROOT, '.git')} ${CONTROL_DIRS.repo}`;
await $({ cwd: CONTROL_DIRS.repo })`git checkout --force ${controlRef}`;
await $({ cwd: CONTROL_DIRS.repo })`${pnpm} install`;
await $({ cwd: CONTROL_DIRS.repo })`${pnpm} build --output-logs=new-only`;
Expand Down Expand Up @@ -192,89 +190,3 @@ try {
}

process.exit(0);

// 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')}`;

if (!REUSE_CONTROL) {
await $`rm -rf ${CONTROL_DIRS.root}`;
await $`mkdir ${CONTROL_DIRS.root}`;
}

if (!REUSE_EXPERIMENT) {
await $`rm -rf ${EXPERIMENT_DIRS.root}`;
await $`mkdir ${EXPERIMENT_DIRS.root}`;
}

// Intentionally use the same folder for both experiment and control to make it easier to
// make changes to the benchmark suite itself and compare the results.
const BENCHMARK_FOLDER = join(pwd, benchmarkFolder);

// make sure that the origin is up to date so we get the right control
await $`git fetch origin`;

// now we can get the ref of the control branch so we can check it out later

console.info({
control: controlBranchName,
experiment: experimentRef,
EXPERIMENT_DIRS,
CONTROL_DIRS,
});

// setup experiment
await mkdirp(EXPERIMENT_DIRS.bench);
await cp();

await buildRepo(EXPERIMENT_DIR, experimentRef, REUSE_EXPERIMENT);

// setup control
await buildRepo(CONTROL_DIR, controlRef, REUSE_CONTROL);

// start build assets

async function buildRepo(directory: string, ref: string, reuse: boolean) {
if (!reuse) {
await $`rm -rf ${directory}`;
await $`mkdir ${directory}`;
}

await within(async () => {
// the benchmark directory is located in `packages/@glimmer/benchmark` in each of the
// experiment and control checkouts
const benchDir = join(directory, 'benchmark', 'benchmarks', 'krausest');

cd(directory);

// write the `pwd` to the output to make it easier to debug if something goes wrong
await $`pwd`;

if (reuse) {
await $`git fetch`;
} else {
// clone the raw git repo for the experiment
await $`git clone ${join(ROOT, '.git')} .`;
}

// checkout the repo to the HEAD of the current branch
await $`git checkout --force ${ref}`;

// recreate the benchmark directory
await $`rm -rf ./benchmark`;
// intentionally use the same folder for both experiment and control
await $`cp -r ${BENCHMARK_FOLDER} ./benchmark`;

// `pnpm install` and build the repo
await $({ nothrow: true })`pnpm install`;
// await $`pnpm build`;

if (!reuse) {
await buildKrausestDeps({ roots: { benchmark: benchDir, workspace: directory } });
}

// build the benchmarks using vite
cd(benchDir);
await $`pnpm vite build`;
});
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Namespace } from '@glimmer/interfaces';
import { NS_HTML, NS_MATHML, NS_SVG } from '@glimmer/constants';

import { defineComponent, jitSuite, RenderTest, test } from '..';
import { defineComponent, jitSuite, RenderTest, test } from '@glimmer-workspace/integration-tests';

class MathElementTest extends RenderTest {
static suiteName = '<math>';
Expand Down

0 comments on commit 2b8b1f6

Please sign in to comment.