Skip to content

Commit 7f4f3f0

Browse files
authored
Improve benchmark setup (#1647)
* Improve benchmark setup The main improvement is cloning from your local `.git` directory rather than the remote. There are also some minor ergonomic improvements to the output. * Fix lint error * Fix typescript errors in js files * Silence a bunch of lint warnings
1 parent 153afe9 commit 7f4f3f0

File tree

38 files changed

+169
-124
lines changed

38 files changed

+169
-124
lines changed

benchmark/benchmarks/krausest/vite.config.mts

+17-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ const packagePath = (name: string) => {
1515
};
1616

1717
export default defineConfig({
18-
plugins: [benchmark()],
18+
plugins: [importMeta(), benchmark()],
19+
preview: {
20+
strictPort: true,
21+
},
1922
resolve: {
2023
alias: {
2124
'@glimmer-workspace/benchmark-env': '@glimmer-workspace/benchmark-env/index.ts',
@@ -27,22 +30,31 @@ export default defineConfig({
2730
},
2831
});
2932

33+
function importMeta(): Plugin {
34+
return {
35+
name: 'define custom import.meta.env',
36+
async transform(code) {
37+
if (code.includes('import.meta.env.VM_LOCAL_DEV')) {
38+
return code.replace(/import.meta.env.VM_LOCAL_DEV/g, 'false');
39+
}
40+
return undefined;
41+
},
42+
enforce: 'pre',
43+
};
44+
}
45+
3046
function benchmark(): Plugin {
3147
return {
3248
enforce: 'pre',
3349
name: '@glimmer/benchmark',
3450
resolveId(id) {
3551
if (id === '@glimmer/env') {
3652
return '\0@glimmer/env';
37-
} else if (id === '@glimmer/local-debug-flags') {
38-
return '\0@glimmer/local-debug-flags';
3953
}
4054
},
4155
load(id) {
4256
if (id === '\0@glimmer/env') {
4357
return `export const DEBUG = false;`;
44-
} else if (id === '\0@glimmer/local-debug-flags') {
45-
return `export const LOCAL_SHOULD_LOG = false;`;
4658
}
4759
/** @type {string | undefined} */
4860
let result: string | undefined;

bin/setup-bench.mjs

+18-28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import 'zx/globals';
22
import os from 'node:os';
33
import { join } from 'node:path';
4+
import chalk from 'chalk';
5+
6+
const ROOT = new URL('..', import.meta.url).pathname;
7+
$.verbose = true;
48

59
/*
610
@@ -80,21 +84,6 @@ const isMacOs = os.platform() === 'darwin';
8084

8185
const BENCHMARK_FOLDER = join(pwd, benchmarkFolder);
8286

83-
const rawUpstreamUrl = await $`git ls-remote --get-url upstream`;
84-
const rawOriginUrl = await $`git ls-remote --get-url origin`;
85-
let originUrlStr = rawOriginUrl.toString().trim();
86-
let upstreamUrlStr = rawUpstreamUrl.toString().trim();
87-
88-
if (upstreamUrlStr === 'upstream') {
89-
// if we not inside fork, falling back to origin
90-
upstreamUrlStr = originUrlStr;
91-
}
92-
93-
if (FORK_NAME && FORK_NAME !== 'glimmerjs/glimmer-vm') {
94-
// if PR from fork, we need to resolve fork's commit
95-
originUrlStr = originUrlStr.replace('glimmerjs/glimmer-vm', FORK_NAME);
96-
}
97-
9887
const CONTROL_PORT = 4020;
9988
const EXPERIMENT_PORT = 4021;
10089
const CONTROL_URL = `http://localhost:${CONTROL_PORT}`;
@@ -105,15 +94,15 @@ const EXPERIMENT_URL = `http://localhost:${EXPERIMENT_PORT}`;
10594
// setup experiment
10695
await within(async () => {
10796
await cd(EXPERIMENT_DIR);
108-
await $`git clone ${originUrlStr} .`;
97+
await $`git clone ${join(ROOT, '.git')} .`;
10998
await $`git checkout ${experimentBranchName}`;
11099
await $`rm -rf ./benchmark`;
111100
await $`cp -r ${BENCHMARK_FOLDER} ./benchmark`;
112101

113-
console.info('installing experiment source');
114-
await $`pnpm install --no-frozen-lockfile`.quiet();
115-
console.info('building experiment source, may take a while');
116-
await $`pnpm build`.quiet();
102+
console.info(`$ pnpm install --frozen-lockfile ${chalk.gray('[experiment]')}`);
103+
await $`pnpm install --frozen-lockfile`.quiet();
104+
console.info(`$ pnpm build ${chalk.gray('[experiment]')}`);
105+
await spinner(() => $`pnpm build`.quiet());
117106

118107
if (isMacOs) {
119108
await $`find ./packages -name 'package.json' -exec sed -i '' 's|"main": "index.ts",|"main": "./dist/prod/index.js","module": "./dist/prod/index.js",|g' {} \\;`;
@@ -132,15 +121,16 @@ await within(async () => {
132121
// setup control
133122
await within(async () => {
134123
await cd(CONTROL_DIR);
135-
await $`git clone ${upstreamUrlStr} .`;
136-
await $`git checkout ${controlBranchName}`;
124+
await $`git clone ${join(ROOT, '.git')} .`;
125+
await $`git fetch origin`;
126+
await $`git reset --hard origin/${controlBranchName}`;
137127
await $`rm -rf ./benchmark`;
138128
await $`cp -r ${BENCHMARK_FOLDER} ./benchmark`;
139129

140-
console.info('installing control source');
141-
await $`pnpm install --no-frozen-lockfile`.quiet();
142-
console.info('building control source, may take a while');
143-
await $`pnpm build`.quiet();
130+
console.info(`$ pnpm install --frozen-lockfile ${chalk.gray('[control]')}`);
131+
await $`pnpm install --frozen-lockfile`.quiet();
132+
console.info(`$ pnpm build ${chalk.gray('[control]')}`);
133+
await spinner(() => $`pnpm build`.quiet());
144134

145135
if (isMacOs) {
146136
await $`find ./packages -name 'package.json' -exec sed -i '' 's|"main": "index.ts",|"main": "./dist/prod/index.js","module": "./dist/prod/index.js",|g' {} \\;`;
@@ -157,8 +147,8 @@ await within(async () => {
157147
});
158148

159149
console.info({
160-
upstreamUrlStr,
161-
originUrlStr,
150+
control: controlBranchName,
151+
experiment: experimentBranchName,
162152
EXPERIMENT_DIR,
163153
CONTROL_DIR,
164154
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
"typescript": "^5.0.4",
107107
"vite": "^5.0.12",
108108
"xo": "^0.54.2",
109-
"zx": "^7.2.3"
109+
"zx": "^8.1.9"
110110
},
111111
"changelog": {
112112
"repo": "glimmerjs/glimmer-vm",

packages/@glimmer-workspace/build/lib/config.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,8 @@ export class Package {
256256
}
257257

258258
/**
259-
* @typedef {object} Formats
260-
* @property {boolean} [ esm ] enabled by default
261-
* @property {boolean} [ cjs ] enabled by default until eslint-plugin-ember and ember-source no longer need it
259+
* @typedef {{esm?: boolean, cjs?: boolean}} Formats
260+
* @param {Formats} [formats] enabled by default
262261
*
263262
* @returns {import("rollup").RollupOptions[] | import("rollup").RollupOptions}
264263
*/
@@ -371,7 +370,7 @@ export class Package {
371370
typescript(this.#package, {
372371
target: ScriptTarget.ES2021,
373372
module: ModuleKind.CommonJS,
374-
moduleResolution: ModuleResolutionKind.NodeJs,
373+
moduleResolution: ModuleResolutionKind.Node16,
375374
}),
376375
],
377376
}));

packages/@glimmer-workspace/test-utils/lib/guard.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Expand, Maybe, Present } from '@glimmer/interfaces';
22
import { isPresent } from '@glimmer/util';
33

4+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
45
export type NTuple<N extends number, Type, T extends any[] = []> = T['length'] extends N
56
? T
67
: NTuple<N, Type, [...T, Type]>;

packages/@glimmer-workspace/tsconfig.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
"compilerOptions": {
33
"composite": true,
44
"baseUrl": "..",
5-
5+
"allowJs": true,
66
"target": "esnext",
77
"module": "esnext",
88
"moduleResolution": "bundler",
99
"allowSyntheticDefaultImports": true,
1010
"experimentalDecorators": true,
1111
"verbatimModuleSyntax": true,
12-
1312
"outDir": "../../ts-dist/@glimmer-workspace",
14-
1513
"strict": true,
1614
"suppressImplicitAnyIndexErrors": false,
1715
"useDefineForClassFields": false,

packages/@glimmer/debug/lib/debug.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export function debug(
9696
let metadata = opcodeMetadata(op.type, isMachine);
9797

9898
if (!metadata) {
99-
throw new Error(`Missing Opcode Metadata for ${op}`);
99+
throw new Error(`Missing Opcode Metadata for ${op.type}`);
100100
}
101101

102102
let out = Object.create(null);

packages/@glimmer/debug/lib/metadata.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const OPERAND_TYPES = [
1919
];
2020

2121
function isOperandType(s: string): s is OperandType {
22+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2223
return OPERAND_TYPES.indexOf(s as any) !== -1;
2324
}
2425

packages/@glimmer/debug/lib/stack-check.ts

+1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ class SafeStringChecker implements Checker<SafeString> {
290290

291291
validate(value: unknown): value is SafeString {
292292
return (
293+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
293294
typeof value === 'object' && value !== null && typeof (value as any).toHTML === 'function'
294295
);
295296
}

packages/@glimmer/global-context/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
/**
23
* This package contains global context functions for Glimmer. These functions
34
* are set by the embedding environment and must be set before initial render.

packages/@glimmer/interfaces/lib/compile/wire-format/api.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export type ExpressionSexpOpcodeMap = {
6666
[TSexpOpcode in TupleExpression[0]]: Extract<TupleExpression, { 0: TSexpOpcode }>;
6767
};
6868

69-
export interface SexpOpcodeMap extends ExpressionSexpOpcodeMap, StatementSexpOpcodeMap { }
69+
export interface SexpOpcodeMap extends ExpressionSexpOpcodeMap, StatementSexpOpcodeMap {}
7070
export type SexpOpcode = keyof SexpOpcodeMap;
7171

7272
export namespace Core {
@@ -372,7 +372,7 @@ export type SerializedTemplateBlock = [
372372
hasDebug: boolean,
373373
// upvars
374374
upvars: string[],
375-
lexicalSymbols?: string[]
375+
lexicalSymbols?: string[],
376376
];
377377

378378
/**

packages/@glimmer/interfaces/lib/runtime/arguments.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export interface ArgumentsDebug {
6767
}
6868

6969
export interface ArgumentError {
70+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7071
error: any;
7172
}
7273

packages/@glimmer/interfaces/lib/runtime/environment.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ export interface Environment {
4545

4646
isInteractive: boolean;
4747
debugRenderTree?: DebugRenderTree | undefined;
48+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4849
isArgumentCaptureError?: ((error: any) => boolean) | undefined;
4950
}

packages/@glimmer/manager/lib/internal/defaults.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type FnArgs<Args extends Arguments = Arguments> =
1010
| [...Args['positional'], Args['named']]
1111
| [...Args['positional']];
1212

13+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1314
type AnyFunction = (...args: any[]) => unknown;
1415

1516
interface State {

packages/@glimmer/manager/lib/public/component.ts

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export class CustomComponentManager<O extends Owner, ComponentInstance>
126126
throw new Error(
127127
`Custom component managers must have a \`capabilities\` property that is the result of calling the \`capabilities('3.13')\` (imported via \`import { capabilities } from '@ember/component';\`). Received: \`${JSON.stringify(
128128
delegate.capabilities
129+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
129130
)}\` for: \`${delegate}\``
130131
);
131132
}
@@ -150,6 +151,7 @@ export class CustomComponentManager<O extends Owner, ComponentInstance>
150151
}
151152

152153
getDebugName(definition: ComponentDefinitionState): string {
154+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
153155
return typeof definition === 'function' ? definition.name : definition.toString();
154156
}
155157

packages/@glimmer/manager/lib/public/helper.ts

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export class CustomHelperManager<O extends Owner = Owner> implements InternalHel
8282
throw new Error(
8383
`Custom helper managers must have a \`capabilities\` property that is the result of calling the \`capabilities('3.23')\` (imported via \`import { capabilities } from '@ember/helper';\`). Received: \`${JSON.stringify(
8484
delegate.capabilities
85+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
8586
)}\` for: \`${delegate}\``
8687
);
8788
}

packages/@glimmer/manager/lib/public/modifier.ts

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class CustomModifierManager<O extends Owner, ModifierInstance>
8585
throw new Error(
8686
`Custom modifier managers must have a \`capabilities\` property that is the result of calling the \`capabilities('3.22')\` (imported via \`import { capabilities } from '@ember/modifier';\`). Received: \`${JSON.stringify(
8787
delegate.capabilities
88+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
8889
)}\` for: \`${delegate}\``
8990
);
9091
}

packages/@glimmer/manager/lib/util/args-proxy.ts

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class PositionalArgsProxy implements ProxyHandler<[]> {
112112
return valueForRef(positional[parsed]!);
113113
}
114114

115+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
115116
return (target as any)[prop];
116117
}
117118

0 commit comments

Comments
 (0)