Repository navigation
bun test --isolate: experimental global-reuse path to keep dependency JIT code alive #36810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
86b8b4b
bun test --isolate: experimental global-reuse path to keep dependency…
robobun f74845e
clippy: use &raw mut for FFI out-params
robobun 47caca0
trim doc comments flagged by comment-cop
robobun 29325ea
P2: pristine-global fingerprint + fallback, preload-once, --isolate=f…
robobun 0099397
[autofix.ci] apply automated fixes
autofix-ci[bot] 8fc12e5
guard MarkedArgumentBuffer overflow in the cjs eviction collect
robobun 8b4094f
reuse: preserve preload setDefaultTimeout across reused files; bound …
robobun de5a1a3
ci: retrigger
robobun 80b4518
fingerprint: exception check after reifyAllStaticProperties; mixed-se…
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // Generates a JIT-heavy suite: FILES test files that each import a handful of | ||
| // real-world dependencies (zod, date-fns, lodash-es) and call into them enough | ||
| // times that JSC tiers the dependency functions up into DFG/FTL. Under | ||
| // `--isolate` with a fresh global per file, every file re-links every | ||
| // dependency module and re-tiers every hot function from scratch; the | ||
| // experimental reuse-global path keeps dependency module records alive so the | ||
| // optimized CodeBlocks survive. | ||
| // | ||
| // Usage: | ||
| // bun bench/test/app/setup.ts | ||
| // hyperfine --warmup 1 \ | ||
| // -n 'fresh global' 'bun test --isolate bench/test/app/suite' \ | ||
| // -n 'reuse global' 'BUN_FEATURE_FLAG_EXPERIMENTAL_TEST_ISOLATE_REUSE_GLOBAL=1 bun test --isolate bench/test/app/suite' | ||
| // | ||
| // To see JIT compile time directly: | ||
| // BUN_JSC_reportTotalCompileTimes=1 bun test --isolate bench/test/app/suite | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| import { mkdirSync, rmSync, writeFileSync } from "node:fs"; | ||
|
|
||
| const FILES = Number(process.env.FILES ?? 128); | ||
| const ITERS = Number(process.env.ITERS ?? 2000); | ||
| const root = import.meta.dir + "/suite"; | ||
|
|
||
| rmSync(root, { recursive: true, force: true }); | ||
| mkdirSync(root, { recursive: true }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| // Shared project-side helper: lives outside node_modules so the reuse path | ||
| // still evicts it (project modules must always be fresh). | ||
| writeFileSync( | ||
| `${root}/hot.ts`, | ||
| `import { z } from "zod"; | ||
| import { format, addDays, differenceInMilliseconds, parseISO } from "date-fns"; | ||
| import { chunk, sortBy, uniqBy, groupBy, sumBy } from "lodash-es"; | ||
|
|
||
| export const schema = z.object({ | ||
| id: z.number().int().positive(), | ||
| name: z.string().min(1).max(64), | ||
| email: z.string().email(), | ||
| tags: z.array(z.string()).max(8), | ||
| createdAt: z.string(), | ||
| }); | ||
| export type Row = z.infer<typeof schema>; | ||
|
|
||
| export function hot(iters: number) { | ||
| const base = parseISO("2024-01-01T00:00:00.000Z"); | ||
| const rows: Row[] = []; | ||
| for (let i = 0; i < 64; i++) { | ||
| rows.push( | ||
| schema.parse({ | ||
| id: i + 1, | ||
| name: "user" + (i % 7), | ||
| email: "u" + i + "@example.com", | ||
| tags: ["t" + (i % 3), "t" + (i % 5)], | ||
| createdAt: format(addDays(base, i % 30), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx"), | ||
| }), | ||
| ); | ||
| } | ||
| let acc = 0; | ||
| for (let k = 0; k < iters; k++) { | ||
| const grouped = groupBy(rows, r => r.name); | ||
| const sorted = sortBy(rows, r => r.id); | ||
| const uniq = uniqBy(rows, r => r.tags[0]); | ||
| const chunks = chunk(sorted, 8); | ||
| acc += sumBy(uniq, r => r.id); | ||
| acc += chunks.length; | ||
| acc += Object.keys(grouped).length; | ||
| acc += differenceInMilliseconds(parseISO(rows[k & 63].createdAt), base) & 1023; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
| return acc; | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| for (let f = 0; f < FILES; f++) { | ||
| writeFileSync( | ||
| `${root}/t${String(f).padStart(3, "0")}.test.ts`, | ||
| `import { hot } from "./hot"; | ||
| test("t${f}", () => { | ||
| const v = hot(${ITERS}); | ||
| expect(typeof v).toBe("number"); | ||
| expect(v > 0).toBe(true); | ||
| }); | ||
| `, | ||
| ); | ||
| } | ||
|
|
||
| console.log(`wrote ${root}/hot.ts + ${FILES} test files (ITERS=${ITERS})`); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.