Public: anyone can read this; the crew can change it.
A forge on a migrated, empty data directory is ready in under 1.5 s, so the real rolls leave the SLOW list #17009
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/12493-a-forge-on-a-migrated-empty-data-directo → main 0 commits fork 3 threads · 3 unresolved
2 files
changed +25
−3
scripts/rehearse-roll.ts +13 −2
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | * environment, never this shell's. |
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | import { cpSync, mkdirSync, mkdtempSync, rmSync } from "node:fs"; | |
| 22 | import { cpSync, existsSync, mkdirSync, mkdtempSync, rmSync } from "node:fs"; | |
| 23 | 23 | import { tmpdir } from "node:os"; |
| 24 | 24 | import { join, resolve } from "node:path"; |
| 25 | 25 | import { freePort, lostPort, PORT_RETRIES } from "../src/kernel/port.ts"; |
| @@ -50,6 +50,17 @@ interface Forge { | ||
| 50 | 50 | readonly portsLost: number; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | /** | |
| 54 | * The file a checkout boots from: its `src/main.ts`, or the `main.js` of a bundle | |
| 55 | * (`bun build --target bun --outdir <checkout> src/main.ts`) when it has no source. | |
| 56 | * A bundle skips parsing the source tree, which is most of a boot's first seconds (#12493). | |
| 57 | */ | |
| 58 | function entryOf(checkout: string): string { | |
| 59 | const source = join(checkout, "src", "main.ts"); | |
| 60 | const bundle = join(checkout, "main.js"); | |
| 61 | return !existsSync(source) && existsSync(bundle) ? bundle : source; | |
| 62 | } | |
| 63 | ||
| 53 | 64 | /** |
| 54 | 65 | * A forge on a port free a moment ago. Between the probe that found it and |
| 55 | 66 | * the forge's bind, another process can take it — a gate shard's listener, |
| @@ -79,7 +90,7 @@ async function start( | ||
| 79 | 90 | const v = process.env[pass]; |
| 80 | 91 | if (v !== undefined) env[pass] = v; |
| 81 | 92 | } |
| 82 | const proc = Bun.spawn([process.execPath, join(checkout, "src", "main.ts")], { | |
| 93 | const proc = Bun.spawn([process.execPath, entryOf(checkout)], { | |
| 83 | 94 | cwd: checkout, |
| 84 | 95 | env, |
| 85 | 96 | stdin: "ignore", |
test/helpers/real-roll.ts +12 −1
| @@ -11,16 +11,26 @@ | ||
| 11 | 11 | import { mkdtempSync, rmSync } from "node:fs"; |
| 12 | 12 | import { tmpdir } from "node:os"; |
| 13 | 13 | import { join } from "node:path"; |
| 14 | import { bundleBoot } from "./bundle-boot.ts"; | |
| 14 | 15 | import { createApp } from "../../src/app.ts"; |
| 15 | 16 | import { rehearse } from "../../scripts/rehearse-roll.ts"; |
| 16 | 17 | import { parseArgs } from "../../scripts/rehearsal.ts"; |
| 17 | 18 | |
| 18 | 19 | export async function realRoll(lingerS: number): Promise<Awaited<ReturnType<typeof rehearse>>> { |
| 19 | 20 | const seeded = join(mkdtempSync(join(tmpdir(), "forge-rehearsal-seed-")), "data"); |
| 21 | const built = mkdtempSync(join(tmpdir(), "forge-rehearsal-bundle-")); | |
| 20 | 22 | try { |
| 21 | 23 | createApp({ dataDir: seeded, port: 0 }).close(); |
| 24 | // Both forges boot from one bundle of src/main.ts, built once: booting the source | |
| 25 | // loads about 4,000 modules each time, 3 s or more of a roll's two boots (#12493). | |
| 26 | // So these rolls rehearse the bundle, not the `bun src/main.ts` boot production runs: | |
| 27 | // the roll's handover, drain and probes are the same code, but the workers main.ts | |
| 28 | // starts by file (`new Worker(new URL("./x.ts", …))`: looks, scans, run logs) are not | |
| 29 | // in the bundle. Nothing in a roll with FORGE_APPS and FORGE_CHECKS off reaches them; | |
| 30 | // the source boot itself is held by the tests that spawn src/main.ts. | |
| 31 | bundleBoot(built, /* bytecode */ false); // false: a plain main.js, which `entryOf` finds in `built` | |
| 22 | 32 | return await rehearse({ |
| 23 | ...parseArgs([], `${import.meta.dir}/../..`), | |
| 33 | ...parseArgs([], built), | |
| 24 | 34 | from: seeded, |
| 25 | 35 | // Room for a slow boot and a long linger on a busy machine (#2020). |
| 26 | 36 | seconds: 30, |
| @@ -36,5 +46,6 @@ export async function realRoll(lingerS: number): Promise<Awaited<ReturnType<type | ||
| 36 | 46 | }); |
| 37 | 47 | } finally { |
| 38 | 48 | rmSync(join(seeded, ".."), { recursive: true, force: true }); |
| 49 | rmSync(built, { recursive: true, force: true }); | |
| 39 | 50 | } |
| 40 | 51 | } |
new above
offline
This new doc block splits start()'s existing doc comment (about the port race) from start(). Put entryOf and its comment above that older comment.