Skip to content
Open
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
18 changes: 18 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,24 @@ updates:
# job. Keep its Wasmtime release series in step with the root workspace.
- dependency-name: "wasmtime"

# The compiler experiment resolves its own locked benchmark dependencies.
# Published measurements retain the lockfile from their recorded commit.
- package-ecosystem: "cargo"
directory: "/experiments/mixed-execution-plan"
schedule:
interval: "weekly"
commit-message:
prefix: "chore(deps)"
allow:
- dependency-name: "tokio"
- dependency-name: "serde_json"
groups:
compiler-benchmark-dependencies:
patterns:
- "*"
ignore:
- dependency-name: "wasmtime"

# npm / pnpm.
#
# Important decision: the five pnpm lockfiles in this repo had no
Expand Down
10 changes: 10 additions & 0 deletions crates/bashkit-wasm/__test__/bashkit-wasm.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ test("options: maxLoopIterations bounds runaway loops", () => {
);
});

test("sync: word iteration stays synchronous with arithmetic in its body", () => {
const bash = new Bash();
const result = bash.executeSync(
"total=0; for i in {1..100}; do ((total+=i)); done; printf '%s\\n' \"$total\"",
);
assert.equal(result.stdout, "5050\n");
assert.equal(result.stderr, "");
assert.equal(result.exitCode, 0);
});

test("output is capped and reports truncation", () => {
const bash = new Bash();
const r = bash.executeSync(`printf '${"x".repeat(1_100_000)}'`);
Expand Down
72 changes: 72 additions & 0 deletions crates/bashkit-wasm/__test__/size-budget.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { spawnSync } from "node:child_process";
import { fileURLToPath } from "node:url";
import { artifactBudget, checkArtifactBudget } from "../bench/artifact.mjs";

function withPackage(run) {
const pkg = mkdtempSync(join(tmpdir(), "bashkit-budget-"));
try { run(pkg); } finally { rmSync(pkg, { recursive: true, force: true }); }
}

test("size: only an explicit compiler feature selects the separate gzip cap", () => {
withPackage(pkg => {
const ordinary = artifactBudget(pkg);
assert.equal(ordinary.profile, "default");
assert.equal(ordinary.limits.gzip, 3100000);
for (const features of [[], ["terminal"], ["bashkit/experimental_execution_plan_extra"]]) {
writeFileSync(join(pkg, "build-info.json"), JSON.stringify({ features }));
assert.deepEqual(artifactBudget(pkg), ordinary);
}
for (const feature of ["experimental_execution_plan", "bashkit/experimental_execution_plan"]) {
writeFileSync(join(pkg, "build-info.json"), JSON.stringify({ features: ["terminal", feature] }));
const compiled = artifactBudget(pkg);
assert.equal(compiled.profile, "execution-plan");
assert.deepEqual(compiled.limits, { ...ordinary.limits, gzip: 3120000 });
const report = { total: { raw: 7900000, gzip: 3110000, brotli: 2200000 } };
assert.throws(() => checkArtifactBudget(report, ordinary), /gzip/);
checkArtifactBudget(report, compiled);
for (const [kind, limit] of Object.entries(compiled.limits)) {
assert.throws(() => checkArtifactBudget({ total: { ...report.total, [kind]: limit + 1 } }, compiled), new RegExp(kind));
}
}
});
});

test("size: malformed feature identity fails rather than selecting a cap", () => {
withPackage(pkg => {
for (const features of [undefined, "experimental_execution_plan", [null]]) {
writeFileSync(join(pkg, "build-info.json"), JSON.stringify({ features }));
assert.throws(() => artifactBudget(pkg), /invalid build-info features/);
}
});
});

test("size: the artifact CLI enforces the selected build profile", () => {
withPackage(pkg => {
const header = Buffer.from([0, 97, 115, 109, 1, 0, 0, 0]);
// A valid custom section exceeds the raw cap while compressing easily.
const padding = Buffer.alloc(8000001);
const leb = [];
for (let size = padding.length; ; size >>>= 7) {
leb.push((size & 127) | (size > 127 ? 128 : 0));
if (size <= 127) break;
}
const oversized = Buffer.concat([header, Buffer.from([0, ...leb]), padding]);
for (const features of [[], ["bashkit/experimental_execution_plan"]]) {
writeFileSync(join(pkg, "bashkit_wasm_bg.wasm"), header);
writeFileSync(join(pkg, "build-info.json"), JSON.stringify({ features }));
const command = [fileURLToPath(new URL("../bench/artifact.mjs", import.meta.url)), pkg, "--check"];
const run = spawnSync(process.execPath, command, { encoding: "utf8" });
assert.equal(run.status, 0, run.stderr);
assert.equal(JSON.parse(run.stdout).budgetProfile, features.length ? "execution-plan" : "default");
writeFileSync(join(pkg, "bashkit_wasm_bg.wasm"), oversized);
const rejected = spawnSync(process.execPath, command, { encoding: "utf8" });
assert.notEqual(rejected.status, 0);
assert.match(rejected.stderr, /raw: .* exceeds 8000000 byte budget/);
}
});
});
5 changes: 4 additions & 1 deletion crates/bashkit-wasm/bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ macOS, `/bin/bash` 3.2 is unsuitable) and Node 22+.
- `node crates/bashkit-wasm/bench/artifact.mjs [pkg] [--check]`: raw, gzip-9,
Brotli-11 bytes for the actual JS + WASM load graph, SHA-256 identities, and
WASM code/data/other sections. `--check` applies `size-budget.json`, with about
4-5% headroom above the selected shipping profile. Review new measurements
4-5% headroom above the selected shipping profile. The opt-in execution-plan
build uses the gzip override in `size-budget-execution-plan.json`, selected
from its explicit build-info features; normal package caps stay unchanged.
Review new measurements
before deliberately raising a budget. No wall-clock threshold in CI.
- `node crates/bashkit-wasm/bench/runtime.mjs pkg`: arithmetic, substitution,
jq, and text pipelines; one warmup and seven measured fresh-instance runs.
Expand Down
31 changes: 25 additions & 6 deletions crates/bashkit-wasm/bench/artifact.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,37 @@ export function artifact(pkg) {
}
return { files, total: Object.fromEntries(["raw", "gzip", "brotli"].map(k => [k, files.reduce((n, f) => n + f[k], 0)])), sections };
}

// The optional compiler has its own transfer allowance. The default published
// package keeps its original caps; identity comes from build.sh's metadata.
export function artifactBudget(pkg) {
const base = JSON.parse(readFileSync(new URL("./size-budget.json", import.meta.url)));
const metadata = resolve(pkg, "build-info.json");
if (!existsSync(metadata)) return { profile: "default", limits: base };
const { features } = JSON.parse(readFileSync(metadata));
if (!Array.isArray(features) || features.some(feature => typeof feature !== "string")) {
throw new Error("invalid build-info features");
}
const compiler = features.includes("experimental_execution_plan") || features.includes("bashkit/experimental_execution_plan");
return compiler
? { profile: "execution-plan", limits: { ...base, ...JSON.parse(readFileSync(new URL("./size-budget-execution-plan.json", import.meta.url))) } }
: { profile: "default", limits: base };
}

export function checkArtifactBudget(report, budget) {
for (const [kind, limit] of Object.entries(budget.limits)) {
if (report.total[kind] > limit) throw new Error(`${kind}: ${report.total[kind]} exceeds ${limit} byte budget (${budget.profile})`);
}
}
// Node canonicalizes the module URL, but argv can retain a symlink (e.g. /var
// versus /private/var on macOS). Imports must never run the CLI accidentally.
if (process.argv[1] && existsSync(process.argv[1]) && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
const paths = process.argv.slice(2).filter(arg => arg !== "--check");
if (paths.length > 1) throw new Error("expected one package directory");
const pkg = resolve(paths[0] ?? new URL("../pkg/", import.meta.url).pathname);
const report = artifact(pkg);
const budget = process.argv.includes("--check") ? artifactBudget(pkg) : null;
if (budget) report.budgetProfile = budget.profile;
console.log(JSON.stringify(report, null, 2));
if (process.argv.includes("--check")) {
const budgets = JSON.parse(readFileSync(new URL("./size-budget.json", import.meta.url)));
for (const [kind, budget] of Object.entries(budgets)) {
if (report.total[kind] > budget) throw new Error(`${kind}: ${report.total[kind]} exceeds ${budget} byte budget`);
}
}
if (budget) checkArtifactBudget(report, budget);
}
Loading
Loading