warm-worktrees 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/BENCHMARKS.md +179 -0
  2. package/GUIDE.md +343 -0
  3. package/LICENSE.md +21 -0
  4. package/README.md +79 -2
  5. package/bench/results/adobe.json +1739 -0
  6. package/bench/results/build-lifecycle.json +1618 -0
  7. package/bench/results/cache-selection.json +3155 -0
  8. package/bench/results/cache-tuning.json +1554 -0
  9. package/bench/results/cargo-cache-scans.json +522 -0
  10. package/bench/results/cargo-snapshot-storage.json +1068 -0
  11. package/bench/results/checkout-selection.json +157 -0
  12. package/bench/results/compiler-seeds.json +634 -0
  13. package/bench/results/concurrent-publication.json +7999 -0
  14. package/bench/results/directory-export.json +4501 -0
  15. package/bench/results/firefox-checkout-control.json +4160 -0
  16. package/bench/results/four-worktrees.json +594 -0
  17. package/bench/results/incremental-cache-directories.json +555 -0
  18. package/bench/results/ninja.json +2133 -0
  19. package/bench/results/output-delivery.json +719 -0
  20. package/bench/results/per-checkout-archives.json +7044 -0
  21. package/bench/results/pool-maintenance.json +447 -0
  22. package/bench/results/rebuild-latency.json +138 -0
  23. package/bench/results/seed-scenarios.json +295 -0
  24. package/bench/results/snapshot-reclamation.json +885 -0
  25. package/bench/results/snapshot-writers.json +46 -0
  26. package/bench/results/source-mirror.json +150 -0
  27. package/bench/results/startup.json +703 -0
  28. package/bench/results/swift-scenarios.json +173 -0
  29. package/bench/results/upstream/firefox-ios.json +2395 -0
  30. package/bench/results/upstream/ripgrep.json +3275 -0
  31. package/bench/results/upstream/swift-syntax.json +2305 -0
  32. package/bench/results/upstream/vscode-seeded.json +3181 -0
  33. package/bench/results/upstream/vscode.json +2121 -0
  34. package/dist/Commander-LICENSE +22 -0
  35. package/dist/JSON5-LICENSE +23 -0
  36. package/dist/Zod-LICENSE +21 -0
  37. package/dist/benchmark.js +289 -0
  38. package/dist/cli.js +18337 -0
  39. package/dist/warm-copy.node +0 -0
  40. package/docs/assets/worktrees-cargo.png +0 -0
  41. package/package.json +55 -4
  42. package/profiles.json5 +82 -0
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2012-2018 Aseem Kishore, and [others].
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ [others]: https://github.com/json5/json5/contributors
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Colin McDonnell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,289 @@
1
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
2
+ var __typeError = (msg) => {
3
+ throw TypeError(msg);
4
+ };
5
+ var __using = (stack, value, async) => {
6
+ if (value != null) {
7
+ if (typeof value !== "object" && typeof value !== "function") __typeError("Object expected");
8
+ var dispose, inner;
9
+ if (async) dispose = value[__knownSymbol("asyncDispose")];
10
+ if (dispose === void 0) {
11
+ dispose = value[__knownSymbol("dispose")];
12
+ if (async) inner = dispose;
13
+ }
14
+ if (typeof dispose !== "function") __typeError("Object not disposable");
15
+ if (inner) dispose = function() {
16
+ try {
17
+ inner.call(this);
18
+ } catch (e) {
19
+ return Promise.reject(e);
20
+ }
21
+ };
22
+ stack.push([async, dispose, value]);
23
+ } else if (async) {
24
+ stack.push([async]);
25
+ }
26
+ return value;
27
+ };
28
+ var __callDispose = (stack, error, hasError) => {
29
+ var E = typeof SuppressedError === "function" ? SuppressedError : function(e, s, m, _) {
30
+ return _ = Error(m), _.name = "SuppressedError", _.error = e, _.suppressed = s, _;
31
+ };
32
+ var fail = (e) => error = hasError ? new E(e, error, "An error was suppressed during disposal") : (hasError = true, e);
33
+ var next = (it) => {
34
+ while (it = stack.pop()) {
35
+ try {
36
+ var result = it[1] && it[1].call(it[2]);
37
+ if (it[0]) return Promise.resolve(result).then(next, (e) => (fail(e), next()));
38
+ } catch (e) {
39
+ fail(e);
40
+ }
41
+ }
42
+ if (hasError) throw error;
43
+ };
44
+ return next();
45
+ };
46
+
47
+ // bench/scenarios.ts
48
+ import { execFileSync as execFileSync2 } from "node:child_process";
49
+ import { existsSync, mkdtempDisposableSync } from "node:fs";
50
+ import { tmpdir } from "node:os";
51
+ import { join as join2, resolve } from "node:path";
52
+ import { parseArgs } from "node:util";
53
+
54
+ // src/git/commands.ts
55
+ import { execFileSync } from "node:child_process";
56
+ var gitOutputLimit = 128 * 1024 * 1024;
57
+ var localVariables;
58
+ function gitEnvironment() {
59
+ const env = { ...process.env };
60
+ if (Object.keys(env).some((key) => key.startsWith("GIT_"))) {
61
+ localVariables ??= execFileSync("git", ["rev-parse", "--local-env-vars"], {
62
+ encoding: "utf8"
63
+ }).trimEnd().split("\n");
64
+ for (const key of localVariables) {
65
+ delete env[key];
66
+ }
67
+ }
68
+ return env;
69
+ }
70
+ function git(cwd, ...args) {
71
+ return runGit(gitEnvironment(), cwd, ...args);
72
+ }
73
+ function runGit(env, cwd, ...args) {
74
+ return execFileSync("git", ["--literal-pathspecs", "-C", cwd, ...args], {
75
+ env,
76
+ encoding: "utf8",
77
+ stdio: ["ignore", "pipe", "pipe"],
78
+ maxBuffer: gitOutputLimit
79
+ });
80
+ }
81
+
82
+ // bench/measure.ts
83
+ import { statfsSync } from "node:fs";
84
+ import { setTimeout } from "node:timers/promises";
85
+ async function settledFreeBytes(path) {
86
+ const started = performance.now();
87
+ let previous = freeBytes(path);
88
+ let matches = 0;
89
+ while (performance.now() - started < 15e3) {
90
+ await setTimeout(500);
91
+ const current = freeBytes(path);
92
+ matches = current === previous ? matches + 1 : 0;
93
+ if (matches === 3) {
94
+ return current;
95
+ }
96
+ previous = current;
97
+ }
98
+ throw new Error(
99
+ "Free space kept changing. Use a dedicated, idle volume for --disk-volume."
100
+ );
101
+ }
102
+ function median(values2) {
103
+ const sorted = values2.toSorted((a, b) => a - b);
104
+ const lower = sorted[Math.floor((sorted.length - 1) / 2)];
105
+ const upper = sorted[Math.floor(sorted.length / 2)];
106
+ if (lower === void 0 || upper === void 0) {
107
+ throw new Error("No benchmark samples.");
108
+ }
109
+ return (lower + upper) / 2;
110
+ }
111
+ function freeBytes(path) {
112
+ const { bfree, bsize } = statfsSync(path);
113
+ return bfree * bsize;
114
+ }
115
+
116
+ // bench/sample.ts
117
+ import { mkdirSync, writeFileSync } from "node:fs";
118
+ import { join } from "node:path";
119
+ function createSampleCheckouts(root) {
120
+ const first = join(root, "first");
121
+ const second = join(root, "second");
122
+ mkdirSync(join(first, "Sources"), { recursive: true });
123
+ writeFileSync(
124
+ join(first, "Package.swift"),
125
+ `// swift-tools-version: 5.9
126
+ import PackageDescription
127
+
128
+ let package = Package(
129
+ name: "Sample",
130
+ targets: [.executableTarget(name: "Sample", path: "Sources")]
131
+ )
132
+ `
133
+ );
134
+ writeFileSync(join(first, ".gitignore"), ".build/\n");
135
+ writeProgram(first, "original");
136
+ git(first, "init", "-q", "-b", "main");
137
+ git(first, "add", ".");
138
+ commit(first, "Add sample");
139
+ git(first, "worktree", "add", "-q", "-b", "feature", second);
140
+ writeProgram(second, "feature");
141
+ commit(second, "Change message on feature branch");
142
+ return { first, second };
143
+ }
144
+ function writeProgram(checkout, message) {
145
+ writeFileSync(
146
+ join(checkout, "Sources", "main.swift"),
147
+ `print("${message}")
148
+ `
149
+ );
150
+ }
151
+ function commit(checkout, message) {
152
+ git(
153
+ checkout,
154
+ "-c",
155
+ "user.name=Warm",
156
+ "-c",
157
+ "user.email=warm@example.invalid",
158
+ "commit",
159
+ "--no-gpg-sign",
160
+ "-qam",
161
+ message
162
+ );
163
+ }
164
+
165
+ // bench/scenarios.ts
166
+ var { values } = parseArgs({
167
+ options: {
168
+ runs: { type: "string", default: "5" },
169
+ "disk-volume": { type: "string" }
170
+ }
171
+ });
172
+ var rounds = Number(values.runs);
173
+ if (!Number.isSafeInteger(rounds) || rounds < 2) {
174
+ throw new Error("--runs must be an integer of at least 2.");
175
+ }
176
+ var swift = ["swift", "run", "Sample"];
177
+ var commands = {
178
+ direct: swift,
179
+ warm: [
180
+ process.execPath,
181
+ join2(import.meta.dirname, "cli.js"),
182
+ "run",
183
+ "--raw",
184
+ "--pool-size",
185
+ "1",
186
+ "--",
187
+ ...swift
188
+ ]
189
+ };
190
+ var results = {
191
+ direct: [],
192
+ warm: []
193
+ };
194
+ for (let round = 0; round < rounds; round++) {
195
+ const order = round % 2 === 0 ? ["direct", "warm"] : ["warm", "direct"];
196
+ for (const method of order) {
197
+ results[method].push(await runRound(method, values["disk-volume"]));
198
+ }
199
+ }
200
+ process.stdout.write(
201
+ JSON.stringify(
202
+ {
203
+ rounds,
204
+ direct: summarise(results.direct),
205
+ warm: summarise(results.warm)
206
+ },
207
+ null,
208
+ 2
209
+ ) + "\n"
210
+ );
211
+ async function runRound(method, volume) {
212
+ var _stack = [];
213
+ try {
214
+ const root = __using(_stack, mkdtempDisposableSync(
215
+ resolve(volume ?? tmpdir(), "warm-benchmark-")
216
+ ));
217
+ const { first, second } = createSampleCheckouts(root.path);
218
+ const before = volume === void 0 ? void 0 : await settledFreeBytes(root.path);
219
+ async function build(checkout, expected) {
220
+ const ms = timedBuild(method, checkout, root.path, expected);
221
+ const bytes = before === void 0 ? void 0 : before - await settledFreeBytes(root.path);
222
+ return { ms, bytes };
223
+ }
224
+ const firstBuild = await build(first, "original");
225
+ const unchanged = await build(first, "original");
226
+ writeProgram(first, "working edit");
227
+ const edited = await build(first, "working edit");
228
+ const switched = await build(second, "feature");
229
+ for (const checkout of [first, second]) {
230
+ if (existsSync(join2(checkout, ".build")) !== (method === "direct")) {
231
+ throw new Error(
232
+ `Unexpected SwiftPM build directory layout in ${checkout} for ${method}.`
233
+ );
234
+ }
235
+ }
236
+ const steps = { firstBuild, unchanged, edited, switched };
237
+ return {
238
+ ...byStep((step) => steps[step].ms),
239
+ usedBytesAfterBuild: volume === void 0 ? void 0 : byStep((step) => steps[step].bytes),
240
+ usedBytes: switched.bytes
241
+ };
242
+ } catch (_) {
243
+ var _error = _, _hasError = true;
244
+ } finally {
245
+ __callDispose(_stack, _error, _hasError);
246
+ }
247
+ }
248
+ function timedBuild(method, checkout, root, expected) {
249
+ const [executable, ...args] = commands[method];
250
+ const env = {
251
+ ...gitEnvironment(),
252
+ WARM_HOME: join2(root, "machine"),
253
+ SWIFTPM_BUILD_DIR: ".build",
254
+ SWIFTPM_MODULECACHE_OVERRIDE: join2(root, "modules"),
255
+ CLANG_MODULE_CACHE_PATH: join2(root, "modules")
256
+ };
257
+ const start = performance.now();
258
+ const output = execFileSync2(executable, args, {
259
+ cwd: checkout,
260
+ env,
261
+ encoding: "utf8",
262
+ stdio: ["ignore", "pipe", "pipe"]
263
+ });
264
+ const elapsed = performance.now() - start;
265
+ if (output.trimEnd() !== expected) {
266
+ throw new Error(
267
+ `${method} build in ${checkout} printed ${JSON.stringify(output.trimEnd())}, expected ${JSON.stringify(expected)}.`
268
+ );
269
+ }
270
+ return elapsed;
271
+ }
272
+ function summarise(samples) {
273
+ const disk = samples.flatMap((row) => row.usedBytesAfterBuild ?? []);
274
+ const medianUsedBytesAfterBuild = disk.length ? byStep((step) => median(disk.flatMap((row) => row[step] ?? []))) : void 0;
275
+ return {
276
+ samples,
277
+ medianMs: byStep((step) => median(samples.map((row) => row[step]))),
278
+ medianUsedBytesAfterBuild,
279
+ medianUsedBytes: medianUsedBytesAfterBuild?.switched
280
+ };
281
+ }
282
+ function byStep(value) {
283
+ return {
284
+ firstBuild: value("firstBuild"),
285
+ unchanged: value("unchanged"),
286
+ edited: value("edited"),
287
+ switched: value("switched")
288
+ };
289
+ }