Skip to content

Commit

Permalink
Merge pull request #1649 from glimmerjs/feature/error-recovery-redux-pt3
Browse files Browse the repository at this point in the history
Continue on with error-recovery infra refresh
  • Loading branch information
NullVoxPopuli authored Nov 19, 2024
2 parents 33ed91b + 35817f7 commit 361b214
Show file tree
Hide file tree
Showing 112 changed files with 3,851 additions and 2,305 deletions.
3 changes: 1 addition & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

node_modules/

# output directories
dist/
ts-dist/


# We don't need prettier here
*.md
!packages/**/*.md
*.yaml
*.yml
guides/
10 changes: 7 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
"eslint.validate": ["javascript", "typescript", "json", "jsonc"],
"files.exclude": {
"**/.DS_Store": true,
"**/.git": true
"**/.git": true,
"**/node_modules": true,
"**/dist": true,
"tracerbench-results": true
},
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
Expand All @@ -46,7 +49,7 @@
"typescript.preferences.importModuleSpecifierEnding": "auto",
"typescript.preferences.useAliasesForRenames": false,
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.tsserver.experimental.enableProjectDiagnostics": false,
"typescript.tsserver.experimental.enableProjectDiagnostics": true,
"typescript.workspaceSymbols.scope": "currentProject",
"typescript.experimental.updateImportsOnPaste": true,
"eslint.problems.shortenToSingleLine": true,
Expand Down Expand Up @@ -226,5 +229,6 @@
"rewrap.onSave": false,
"rewrap.autoWrap.enabled": true,
"rewrap.reformat": true,
"rewrap.wholeComment": false
"rewrap.wholeComment": false,
"explorer.excludeGitIgnore": true
}
2 changes: 0 additions & 2 deletions benchmark/benchmarks/krausest/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
"baseUrl": ".",
"allowJs": true,
"checkJs": true,

"target": "es2020",
"module": "esnext",
"moduleResolution": "bundler",
"verbatimModuleSyntax": true,
"noErrorTruncation": true,

"suppressImplicitAnyIndexErrors": false,
"useDefineForClassFields": false,
"exactOptionalPropertyTypes": true,
Expand Down
79 changes: 44 additions & 35 deletions bin/setup-bench.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { readFile, writeFile } from 'node:fs/promises';
const ROOT = new URL('..', import.meta.url).pathname;
$.verbose = true;

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

/*
Expand Down Expand Up @@ -81,8 +82,10 @@ if (!REUSE_CONTROL) {
await $`mkdir ${CONTROL_DIR}`;
}

await $`rm -rf ${EXPERIMENT_DIR}`;
await $`mkdir ${EXPERIMENT_DIR}`;
if (!REUSE_EXPERIMENT) {
await $`rm -rf ${EXPERIMENT_DIR}`;
await $`mkdir ${EXPERIMENT_DIR}`;
}

// 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.
Expand Down Expand Up @@ -138,16 +141,10 @@ console.info({
});

// setup experiment
await within(async () => {
await buildRepo(EXPERIMENT_DIR, experimentRef);
});
await buildRepo(EXPERIMENT_DIR, experimentRef, REUSE_EXPERIMENT);

if (!REUSE_CONTROL) {
// setup control
await within(async () => {
await buildRepo(CONTROL_DIR, controlRef);
});
}
// setup control
await buildRepo(CONTROL_DIR, controlRef, REUSE_CONTROL);

// start build assets
$`cd ${CONTROL_BENCH_DIR} && pnpm vite preview --port ${CONTROL_PORT}`;
Expand Down Expand Up @@ -177,36 +174,48 @@ process.exit(0);
/**
* @param {string} directory the directory to clone into
* @param {string} ref the ref to checkout
* @param {boolean} reuse reuse the existing directory
*/
async function buildRepo(directory, ref) {
// the benchmark directory is located in `packages/@glimmer/benchmark` in each of the
// experiment and control checkouts
const benchDir = join(directory, 'benchmark', 'benchmarks', 'krausest');
async function buildRepo(directory, ref, reuse) {
if (!reuse) {
await $`rm -rf ${directory}`;
await $`mkdir ${directory}`;
}

await cd(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');

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

// clone the raw git repo for the experiment
await $`git clone ${join(ROOT, '.git')} .`;
// write the `pwd` to the output to make it easier to debug if something goes wrong
await $`pwd`;

// checkout the repo to the HEAD of the current branch
await $`git checkout --force ${ref}`;
if (reuse) {
await $`git fetch`;
} else {
// clone the raw git repo for the experiment
await $`git clone ${join(ROOT, '.git')} .`;
}

// recreate the benchmark directory
await $`rm -rf ./benchmark`;
// intentionally use the same folder for both experiment and control
await $`cp -r ${BENCHMARK_FOLDER} ./benchmark`;
// checkout the repo to the HEAD of the current branch
await $`git checkout --force ${ref}`;

// `pnpm install` and build the repo
await $`pnpm install --no-frozen-lockfile`;
await $`pnpm build`;
// recreate the benchmark directory
await $`rm -rf ./benchmark`;
// intentionally use the same folder for both experiment and control
await $`cp -r ${BENCHMARK_FOLDER} ./benchmark`;

// rewrite all `package.json`s to behave like published packages
await rewritePackageJson();
// `pnpm install` and build the repo
await $`pnpm install --no-frozen-lockfile`;
await $`pnpm build`;

// build the benchmarks using vite
await cd(benchDir);
await $`pnpm vite build`;
// rewrite all `package.json`s to behave like published packages
await rewritePackageJson();

// build the benchmarks using vite
await cd(benchDir);
await $`pnpm vite build`;
});
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"tracerbench": "^8.0.1",
"ts-node": "^10.9.1",
"turbo": "^1.9.3",
"typescript": "^5.0.4",
"typescript": "~5.0.4",
"vite": "^5.4.10",
"xo": "^0.54.2",
"zx": "^8.1.9"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
ClassicResolver,
Dict,
Helper,
HelperDefinitionState,
Expand All @@ -16,7 +17,7 @@ import {
} from '@glimmer/manager';
import { EvaluationContextImpl } from '@glimmer/opcode-compiler';
import { artifacts, RuntimeOpImpl } from '@glimmer/program';
import { runtimeContext } from '@glimmer/runtime';
import { runtimeOptions } from '@glimmer/runtime';

import type { UpdateBenchmark } from '../interfaces';

Expand Down Expand Up @@ -84,21 +85,17 @@ export default function createRegistry(): Registry {
const sharedArtifacts = artifacts();
const document = element.ownerDocument as SimpleDocument;
const envDelegate = createEnvDelegate(isInteractive ?? true);
const runtime = runtimeContext(
{
document,
},
envDelegate,
sharedArtifacts,
{
lookupHelper: (name) => helpers.get(name) ?? null,
lookupModifier: (name) => modifiers.get(name) ?? null,
lookupComponent: (name) => components.get(name) ?? null,

lookupBuiltInHelper: () => null,
lookupBuiltInModifier: () => null,
}
);
const resolver = {
lookupHelper: (name) => helpers.get(name) ?? null,
lookupModifier: (name) => modifiers.get(name) ?? null,
lookupComponent: (name) => components.get(name) ?? null,

lookupBuiltInHelper: () => null,
lookupBuiltInModifier: () => null,
} satisfies ClassicResolver;

const runtime = runtimeOptions({ document }, envDelegate, sharedArtifacts, resolver);

const context = new EvaluationContextImpl(
sharedArtifacts,
Expand All @@ -110,7 +107,7 @@ export default function createRegistry(): Registry {
throw new Error(`missing ${entry} component`);
}

return renderBenchmark(context, component, args, element as SimpleElement);
return renderBenchmark(sharedArtifacts, context, component, args, element as SimpleElement);
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
Dict,
EvaluationContext,
ResolvedComponentDefinition,
RuntimeArtifacts,
SimpleElement,
} from '@glimmer/interfaces';
import { NewTreeBuilder, renderComponent, renderSync } from '@glimmer/runtime';
Expand All @@ -12,6 +13,7 @@ import { registerResult } from './create-env-delegate';
import { measureRender } from './util';

export default async function renderBenchmark(
artifacts: RuntimeArtifacts,
context: EvaluationContext,
component: ResolvedComponentDefinition,
args: Dict,
Expand Down
11 changes: 10 additions & 1 deletion packages/@glimmer-workspace/integration-tests/lib/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import type { CapturedArguments, Dict } from '@glimmer/interfaces';
import type { Reference } from '@glimmer/reference';
import { setLocalDebugType } from '@glimmer/debug-util';
import { LOCAL_DEBUG } from '@glimmer/local-debug-flags';
import { createComputeRef } from '@glimmer/reference';
import { reifyNamed, reifyPositional } from '@glimmer/runtime';

export type UserHelper = (args: ReadonlyArray<unknown>, named: Dict<unknown>) => unknown;

export function createHelperRef(helper: UserHelper, args: CapturedArguments): Reference {
return createComputeRef(() => helper(reifyPositional(args.positional), reifyNamed(args.named)));
return createComputeRef(
() => helper(reifyPositional(args.positional), reifyNamed(args.named)),
undefined
);
}

if (LOCAL_DEBUG) {
setLocalDebugType('factory:helper', createHelperRef, { name: 'createHelper' });
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
on,
renderComponent,
renderSync,
runtimeContext,
runtimeOptions,
} from '@glimmer/runtime';
import { assign } from '@glimmer/util';

Expand Down Expand Up @@ -63,7 +63,7 @@ export function JitDelegateContext(
env: EnvironmentDelegate
): EvaluationContext {
let sharedArtifacts = artifacts();
let runtime = runtimeContext(
let runtime = runtimeOptions(
{ document: doc },
env,
sharedArtifacts,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Cursor, Environment, SimpleNode, TreeBuilder } from '@glimmer/interfaces';
import { COMMENT_NODE, ELEMENT_NODE } from '@glimmer/constants';
import { RehydrateBuilder } from '@glimmer/runtime';
import { RehydrateTree } from '@glimmer/runtime';

export class DebugRehydrationBuilder extends RehydrateBuilder {
export class DebugRehydrateTree extends RehydrateTree {
clearedNodes: SimpleNode[] = [];

override remove(node: SimpleNode) {
Expand All @@ -23,6 +23,6 @@ export class DebugRehydrationBuilder extends RehydrateBuilder {
}
}

export function debugRehydration(env: Environment, cursor: Cursor): TreeBuilder {
return DebugRehydrationBuilder.forInitialRender(env, cursor);
export function debugRehydrateTree(env: Environment, cursor: Cursor): TreeBuilder {
return DebugRehydrateTree.forInitialRender(env, cursor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import type { UserHelper } from '../../helpers';
import type { TestModifierConstructor } from '../../modifiers';
import type RenderDelegate from '../../render-delegate';
import type { RenderDelegateOptions } from '../../render-delegate';
import type { DebugRehydrationBuilder } from './builder';
import type { DebugRehydrateTree } from './builder';

import { BaseEnv } from '../../base-env';
import { replaceHTML, toInnerHTML } from '../../dom/simple-utils';
Expand All @@ -41,7 +41,7 @@ import {
import { TestJitRegistry } from '../jit/registry';
import { renderTemplate } from '../jit/render';
import { TestJitRuntimeResolver } from '../jit/resolver';
import { debugRehydration } from './builder';
import { debugRehydrateTree } from './builder';

export interface RehydrationStats {
clearedNodes: SimpleNode[];
Expand Down Expand Up @@ -105,7 +105,7 @@ export class RehydrationDelegate implements RenderDelegate {

getElementBuilder(env: Environment, cursor: Cursor): TreeBuilder {
if (cursor.element instanceof Node) {
return debugRehydration(env, cursor);
return debugRehydrateTree(env, cursor);
}

return serializeBuilder(env, cursor);
Expand Down Expand Up @@ -152,7 +152,7 @@ export class RehydrationDelegate implements RenderDelegate {

// Client-side rehydration
let cursor = { element, nextSibling: null };
let builder = this.getElementBuilder(env, cursor) as DebugRehydrationBuilder;
let builder = this.getElementBuilder(env, cursor) as DebugRehydrateTree;
let result = renderTemplate(
template,
this.clientContext,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Dict, RenderResult, SimpleElement } from '@glimmer/interfaces';
import { renderComponent, renderSync } from '@glimmer/runtime';

import type { DebugRehydrationBuilder } from './builder';
import type { DebugRehydrateTree } from './builder';

import { RehydrationDelegate } from './delegate';

Expand All @@ -17,15 +17,15 @@ export class PartialRehydrationDelegate extends RehydrationDelegate {
): RenderResult {
let cursor = { element, nextSibling: null };
let context = this.clientContext;
let builder = this.getElementBuilder(context.env, cursor) as DebugRehydrationBuilder;
let tree = this.getElementBuilder(context.env, cursor) as DebugRehydrateTree;
let component = this.clientRegistry.lookupComponent(name)!;

let iterator = renderComponent(context, builder, {}, component.state, args);
let iterator = renderComponent(context, tree, {}, component.state, args);

const result = renderSync(context.env, iterator);

this.rehydrationStats = {
clearedNodes: builder.clearedNodes,
clearedNodes: tree.clearedNodes,
};

return result;
Expand Down
Loading

0 comments on commit 361b214

Please sign in to comment.