@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 1,230 lines 46.8 KB
Raw
1 /**
2 * Throughput benchmarks against a **deployed** git-service stack
3 * (DESIGN.md §14–15): turns the estimated scaling table into measured
4 * numbers, one benchmark per named bottleneck.
5 *
6 * These are measurements, not assertions about performance: each case
7 * prints a line and asserts only *correctness* (every operation succeeded),
8 * so the suite can never fail because a datacenter had a slow minute. Read
9 * the printed table to see where the service actually stands.
10 *
11 * Run:
12 * bun run test test/GitBench.e2e.test.ts --profile testing
13 * BENCH_SCALE=4 ... to make every workload 4x bigger
14 *
15 * Skipped under `--fast`.
16 */
17 import * as Cloudflare from "@alchemy.run/cloudflare";
18 import { GitApi } from "@alchemy.run/git/Api";
19 import { expect } from "@alchemy.run/test";
20 import * as Test from "@alchemy.run/test/Alchemy";
21 import * as Data from "effect/Data";
22 import * as Effect from "effect/Effect";
23 import * as Fiber from "effect/Fiber";
24 import * as FileSystem from "effect/FileSystem";
25 import * as HttpApiClient from "effect/http-api/HttpApiClient";
26 import * as HttpClient from "effect/http/HttpClient";
27 import * as HttpClientRequest from "effect/http/HttpClientRequest";
28 import * as Path from "effect/Path";
29 import * as ChildProcess from "effect/process/ChildProcess";
30 import { MinimumLogLevel } from "effect/References";
31 import * as Schedule from "effect/Schedule";
32 import * as Stream from "effect/Stream";
33 import { makeTestStack, TEST_SECRET } from "./fixtures/stack.ts";
34 import { verifyPackResponse } from "./harness/pack.ts";
35
36 const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
37 providers: Cloudflare.providers(),
38 });
39
40 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
41
42 const Stack = makeTestStack("GitBenchStack");
43
44 /** Scales every workload; 1 keeps a full run inside the alarm/test budget. */
45 const SCALE = Number.parseInt(process.env.BENCH_SCALE ?? "1", 10) || 1;
46
47 const skipBench = !!process.env.FAST;
48
49 // ── plumbing ────────────────────────────────────────────────────────────────
50
51 const makeClient = (url: string, token: string) =>
52 HttpApiClient.make(GitApi, {
53 baseUrl: url,
54 transformClient: HttpClient.mapRequest((request) =>
55 request.pipe(HttpClientRequest.bearerToken(token)),
56 ),
57 });
58
59 class ShellError extends Data.TaggedError("ShellError")<{
60 readonly script: string;
61 readonly exitCode: number;
62 readonly stdout: string;
63 readonly stderr: string;
64 }> {
65 override get message(): string {
66 return `bench shell exited ${this.exitCode}\n${this.script}\n${this.stderr}`;
67 }
68 }
69
70 const sh = Effect.fn(function* (cwd: string, script: string) {
71 const handle = yield* ChildProcess.make("sh", ["-ec", script], {
72 cwd,
73 env: {
74 GIT_TERMINAL_PROMPT: "0",
75 GIT_CONFIG_NOSYSTEM: "1",
76 GIT_CONFIG_GLOBAL: "/dev/null",
77 GIT_AUTHOR_NAME: "Bench Bot",
78 GIT_AUTHOR_EMAIL: "bench@example.com",
79 GIT_COMMITTER_NAME: "Bench Bot",
80 GIT_COMMITTER_EMAIL: "bench@example.com",
81 GIT_AUTHOR_DATE: "2026-01-01T00:00:00Z",
82 GIT_COMMITTER_DATE: "2026-01-01T00:00:00Z",
83 },
84 extendEnv: true,
85 });
86 const [exitCode, stdout, stderr] = yield* Effect.all(
87 [
88 handle.exitCode,
89 Stream.mkString(Stream.decodeText(handle.stdout)),
90 Stream.mkString(Stream.decodeText(handle.stderr)),
91 ],
92 { concurrency: 3 },
93 );
94 return { script, exitCode, stdout: stdout.trim(), stderr };
95 }, Effect.timeout("240 seconds"));
96
97 const mustSh = Effect.fn(function* (cwd: string, script: string) {
98 const result = yield* sh(cwd, script);
99 if (result.exitCode !== 0) return yield* new ShellError(result);
100 return result;
101 });
102
103 const tempDir = Effect.gen(function* () {
104 const fs = yield* FileSystem.FileSystem;
105 return yield* fs.makeTempDirectory({ prefix: "git-bench-" });
106 });
107
108 const edgeRetry = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
109 effect.pipe(
110 Effect.timeout("15 seconds"),
111 Effect.retry({ schedule: Schedule.spaced("1500 millis"), times: 40 }),
112 );
113
114 const purgeRepo = Effect.fn(function* (url: string, owner: string, repo: string) {
115 const admin = yield* makeClient(url, TEST_SECRET);
116 yield* admin.repos.delete({ params: { owner, repo } }).pipe(
117 Effect.catchTag("RepoNotFound", () => Effect.void),
118 edgeRetry,
119 );
120 yield* admin.repos.get({ params: { owner, repo } }).pipe(
121 edgeRetry,
122 Effect.as(false),
123 Effect.catchTag("RepoNotFound", () => Effect.succeed(true)),
124 Effect.repeat({
125 schedule: Schedule.spaced("1 second"),
126 until: (gone) => gone,
127 times: 60,
128 }),
129 );
130 });
131
132 const freshRepo = Effect.fn(function* (
133 url: string,
134 owner: string,
135 name: string,
136 options?: { readonly public?: boolean },
137 ) {
138 const admin = yield* makeClient(url, TEST_SECRET);
139 const created = yield* Effect.gen(function* () {
140 yield* purgeRepo(url, owner, name);
141 return yield* admin.repos
142 .create({ payload: { owner, name, public: options?.public } })
143 .pipe(edgeRetry);
144 }).pipe(
145 Effect.retry({
146 while: (error: { readonly _tag?: string }) => error._tag === "RepoAlreadyExists",
147 schedule: Schedule.spaced("1 second"),
148 times: 3,
149 }),
150 );
151 const parsed = new URL(url);
152 return {
153 admin,
154 token: TEST_SECRET,
155 remote: `${parsed.protocol}//x:${TEST_SECRET}@${parsed.host}/${owner}/${name}.git`,
156 };
157 });
158
159 // ── measurement ─────────────────────────────────────────────────────────────
160
161 const results: Array<string> = [];
162
163 /** Times an effect, records a bench line, and returns the value. */
164 const measure = <A, E, R>(
165 label: string,
166 effect: Effect.Effect<A, E, R>,
167 describe: (value: A, ms: number) => string,
168 ) =>
169 Effect.gen(function* () {
170 const started = yield* Effect.sync(() => performance.now());
171 const value = yield* effect;
172 const ms = yield* Effect.sync(() => performance.now() - started);
173 const line = `${label.padEnd(46)} ${describe(value, ms)}`;
174 results.push(line);
175 yield* Effect.logInfo(`[bench] ${line}`);
176 return value;
177 });
178
179 const perSecond = (count: number, ms: number) => `${((count / ms) * 1000).toFixed(1)}/s`;
180
181 const stack = beforeAll(
182 deploy(Stack).pipe(
183 Effect.tap(({ url }) =>
184 Effect.gen(function* () {
185 yield* Effect.logInfo(`git-service deployed at ${url}`);
186 const admin = yield* makeClient(url, TEST_SECRET);
187 yield* admin.repos.list({ query: {} }).pipe(
188 edgeRetry,
189 Effect.retry({
190 schedule: Schedule.spaced("1500 millis"),
191 times: 40,
192 }),
193 );
194 }),
195 ),
196 logLevel,
197 ),
198 );
199
200 afterAll(
201 Effect.gen(function* () {
202 if (results.length > 0) {
203 yield* Effect.logInfo(["", "═══ git-service throughput ═══", ...results, ""].join("\n"));
204 }
205 }),
206 );
207 afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack));
208
209 // ═══════════════════════════════════════════════════════════════════════════
210 // Bottleneck 1 — closure computation / clone bandwidth on deep history
211 // ═══════════════════════════════════════════════════════════════════════════
212
213 test.skipIf(skipBench)(
214 "bench: deep history — push, cold clone, bundle clone, incremental fetch",
215 Effect.gen(function* () {
216 const { url } = yield* stack;
217 const repo = yield* freshRepo(url, "bench", "deep");
218 const tmp = yield* tempDir;
219 const commits = 300 * SCALE;
220
221 // Build the history locally first so the measurement is server-side.
222 yield* mustSh(
223 tmp,
224 `
225 rm -rf work && git -c init.defaultBranch=main clone '${repo.remote}' work
226 cd work
227 i=1
228 while [ $i -le ${commits} ]; do
229 printf 'line %s\\n' $i >> history.txt
230 printf 'file %s\\n' $i > "f$i.txt"
231 git add -A && git commit -q -m "c$i"
232 i=$((i+1))
233 done
234 `,
235 );
236
237 yield* measure(
238 `push ${commits} commits`,
239 mustSh(tmp, `cd work && git push origin main`),
240 (_, ms) => `${(ms / 1000).toFixed(1)}s (${perSecond(commits, ms)} commits)`,
241 );
242
243 // Cold clone: no bundle yet (the post-push alarm needs a moment), so
244 // this measures the dynamic closure walk + pack emission path.
245 yield* measure(
246 "clone (dynamic closure walk)",
247 mustSh(tmp, `rm -rf cold && git clone -q '${repo.remote}' cold`),
248 (_, ms) => `${(ms / 1000).toFixed(2)}s`,
249 );
250
251 // Give the bundle alarm time to cut, then clone again: same repo, same
252 // client, but served as bytes from R2 (DESIGN §12.2).
253 yield* Effect.sleep("6 seconds");
254 yield* measure(
255 "clone (R2 bundle fast path)",
256 mustSh(tmp, `rm -rf warm && git clone -q '${repo.remote}' warm`),
257 (_, ms) => `${(ms / 1000).toFixed(2)}s`,
258 );
259
260 // Incremental fetch of a single new commit — the negotiation path.
261 yield* mustSh(
262 tmp,
263 `cd work && echo tip >> history.txt && git add -A && git commit -q -m tip && git push -q origin main`,
264 );
265 yield* measure(
266 "incremental fetch (1 commit)",
267 mustSh(tmp, `cd cold && git fetch -q origin main`),
268 (_, ms) => `${ms.toFixed(0)}ms`,
269 );
270
271 yield* mustSh(tmp, `cd warm && git fsck --strict`);
272 }).pipe(logLevel),
273 {
274 tags: ["provider:cloudflare", "provider:cloudflare:r2", "provider:cloudflare:worker", "live"],
275 timeout: 900_000,
276 },
277 );
278
279 // ═══════════════════════════════════════════════════════════════════════════
280 // Bottleneck 1/2 — clone TPS and bandwidth under concurrency
281 // ═══════════════════════════════════════════════════════════════════════════
282
283 test.skipIf(skipBench)(
284 "bench: concurrent clone storm (clone TPS on one repo)",
285 Effect.gen(function* () {
286 const { url } = yield* stack;
287 const repo = yield* freshRepo(url, "bench", "storm");
288 const tmp = yield* tempDir;
289 const blobKiB = 256 * SCALE;
290 const clones = 8 * SCALE;
291
292 yield* mustSh(
293 tmp,
294 `
295 rm -rf work && git -c init.defaultBranch=main clone '${repo.remote}' work
296 cd work
297 head -c ${blobKiB * 1024} /dev/urandom > blob.bin
298 i=1; while [ $i -le 20 ]; do printf 'f %s\\n' $i > "f$i.txt"; i=$((i+1)); done
299 git add -A && git commit -q -m payload
300 git push -q origin main
301 `,
302 );
303 // Let the bundle land so the storm hits the fast path.
304 yield* Effect.sleep("6 seconds");
305
306 yield* measure(
307 `${clones} concurrent clones (~${blobKiB} KiB each)`,
308 Effect.all(
309 Array.from({ length: clones }, (_, i) =>
310 mustSh(tmp, `rm -rf c${i} && git clone -q '${repo.remote}' c${i}`),
311 ),
312 { concurrency: clones },
313 ),
314 (_, ms) =>
315 `${(ms / 1000).toFixed(2)}s total, ${perSecond(clones, ms)} clones, ` +
316 `~${((clones * blobKiB) / 1024 / (ms / 1000)).toFixed(1)} MiB/s`,
317 );
318 }).pipe(logLevel),
319 {
320 tags: ["provider:cloudflare", "provider:cloudflare:r2", "provider:cloudflare:worker", "live"],
321 timeout: 900_000,
322 },
323 );
324
325 // ═══════════════════════════════════════════════════════════════════════════
326 // Bottleneck 3 — push serialization (inherent: a ref is a serialization point)
327 // ═══════════════════════════════════════════════════════════════════════════
328
329 test.skipIf(skipBench)(
330 "bench: push TPS, serial and concurrent-to-distinct-branches",
331 Effect.gen(function* () {
332 const { url } = yield* stack;
333 const repo = yield* freshRepo(url, "bench", "push");
334 const tmp = yield* tempDir;
335 const pushes = 10 * SCALE;
336
337 yield* mustSh(
338 tmp,
339 `
340 rm -rf work && git -c init.defaultBranch=main clone '${repo.remote}' work
341 cd work && echo base > base.txt && git add -A && git commit -q -m base
342 git push -q origin main
343 `,
344 );
345
346 yield* measure(
347 `${pushes} serial pushes (same branch)`,
348 mustSh(
349 tmp,
350 `
351 cd work
352 i=1
353 while [ $i -le ${pushes} ]; do
354 printf '%s\\n' $i >> base.txt
355 git add -A && git commit -q -m "p$i"
356 git push -q origin main
357 i=$((i+1))
358 done
359 `,
360 ),
361 (_, ms) => `${(ms / 1000).toFixed(1)}s (${perSecond(pushes, ms)})`,
362 );
363
364 // Distinct branches: admission is by ingest MEMORY, not by count
365 // (DESIGN.md §2.1), so ordinary kilobyte-sized pushes to different
366 // branches should now overlap instead of queueing behind each other.
367 const branches = 4 * SCALE;
368 yield* mustSh(
369 tmp,
370 `
371 cd work
372 i=1
373 while [ $i -le ${branches} ]; do
374 git branch -f "side$i" HEAD
375 printf 'side %s\\n' $i > "side$i.txt"
376 i=$((i+1))
377 done
378 `,
379 );
380 yield* measure(
381 `${branches} concurrent pushes (distinct branches)`,
382 Effect.all(
383 Array.from({ length: branches }, (_, i) =>
384 mustSh(tmp, `cd work && git push -q origin side${i + 1}`),
385 ),
386 { concurrency: branches },
387 ),
388 (_, ms) => `${(ms / 1000).toFixed(2)}s (${perSecond(branches, ms)})`,
389 );
390 }).pipe(logLevel),
391 {
392 tags: ["provider:cloudflare", "provider:cloudflare:r2", "provider:cloudflare:worker", "live"],
393 timeout: 900_000,
394 },
395 );
396
397 // ═══════════════════════════════════════════════════════════════════════════
398 // Bottleneck 4 — Registry singleton (control-plane TPS)
399 // ═══════════════════════════════════════════════════════════════════════════
400
401 test.skipIf(skipBench)(
402 "bench: control plane — repo create/list/delete through the Registry",
403 Effect.gen(function* () {
404 const { url } = yield* stack;
405 const admin = yield* makeClient(url, TEST_SECRET);
406 const repos = 10 * SCALE;
407 const names = Array.from({ length: repos }, (_, i) => `ctl-${i}`);
408
409 yield* Effect.all(
410 names.map((name) => purgeRepo(url, "bench", name)),
411 { concurrency: 5 },
412 );
413
414 yield* measure(
415 `${repos} concurrent repo creates`,
416 Effect.all(
417 names.map((name) => admin.repos.create({ payload: { owner: "bench", name } })),
418 { concurrency: repos },
419 ),
420 (created, ms) => {
421 expect(created.length).toBe(repos);
422 return `${(ms / 1000).toFixed(2)}s (${perSecond(repos, ms)})`;
423 },
424 );
425
426 yield* measure(
427 "repo list (single Registry read)",
428 admin.repos.list({ query: { owner: "bench" } }),
429 (page, ms) => `${page.items.length} rows in ${ms.toFixed(0)}ms`,
430 );
431
432 yield* measure(
433 "resolve-cached repo reads (20 sequential GETs)",
434 Effect.all(
435 Array.from({ length: 20 }, () =>
436 admin.repos.get({ params: { owner: "bench", repo: names[0]! } }),
437 ),
438 { concurrency: 1 },
439 ),
440 (_, ms) => `${(ms / 20).toFixed(0)}ms each (${perSecond(20, ms)})`,
441 );
442
443 yield* Effect.all(
444 names.map((name) =>
445 admin.repos
446 .delete({ params: { owner: "bench", repo: name } })
447 .pipe(Effect.catchTag("RepoNotFound", () => Effect.void)),
448 ),
449 { concurrency: 5 },
450 );
451 }).pipe(logLevel),
452 {
453 tags: ["provider:cloudflare", "provider:cloudflare:r2", "provider:cloudflare:worker", "live"],
454 timeout: 900_000,
455 },
456 );
457
458 // ═══════════════════════════════════════════════════════════════════════════
459 // Bottleneck 6 — compaction throughput (R2 write path)
460 // ═══════════════════════════════════════════════════════════════════════════
461
462 test.skipIf(skipBench)(
463 "bench: compaction — loose rows into an R2 pack, then packed reads",
464 Effect.gen(function* () {
465 const { url } = yield* stack;
466 const repo = yield* freshRepo(url, "bench", "compact");
467 const tmp = yield* tempDir;
468 const files = 200 * SCALE;
469
470 yield* mustSh(
471 tmp,
472 `
473 rm -rf work && git -c init.defaultBranch=main clone '${repo.remote}' work
474 cd work
475 i=1
476 while [ $i -le ${files} ]; do
477 head -c 4096 /dev/urandom | base64 > "b$i.txt"
478 i=$((i+1))
479 done
480 git add -A && git commit -q -m payload
481 git push -q origin main
482 `,
483 );
484
485 const before = yield* repo.admin.repos.get({
486 params: { owner: "bench", repo: "compact" },
487 });
488
489 yield* measure(
490 `compact ${before.objects.loose} loose objects into R2`,
491 Effect.gen(function* () {
492 yield* repo.admin.repos.compact({
493 params: { owner: "bench", repo: "compact" },
494 });
495 return yield* repo.admin.repos.get({ params: { owner: "bench", repo: "compact" } }).pipe(
496 Effect.map((found) => found.objects),
497 Effect.repeat({
498 schedule: Schedule.spaced("500 millis"),
499 until: (objects: { loose: number; packed: number }) =>
500 objects.packed > 0 && objects.loose === 0,
501 times: 120,
502 }),
503 );
504 }),
505 (objects, ms) =>
506 `${objects.packed} packed, ${(objects.bytes / 1024 / 1024).toFixed(1)} MiB in ${(ms / 1000).toFixed(1)}s`,
507 );
508
509 // Every object now reads through ranged R2 GETs.
510 yield* measure(
511 "clone from a fully packed repo (ranged R2 reads)",
512 mustSh(tmp, `rm -rf packed && git clone -q '${repo.remote}' packed`),
513 (_, ms) => `${(ms / 1000).toFixed(2)}s`,
514 );
515 yield* mustSh(tmp, `cd packed && git fsck --strict`);
516 }).pipe(logLevel),
517 {
518 tags: ["provider:cloudflare", "provider:cloudflare:r2", "provider:cloudflare:worker", "live"],
519 timeout: 900_000,
520 },
521 );
522
523 // ═══════════════════════════════════════════════════════════════════════════
524 // Bottleneck 1/2 — SERVER-side clone capacity (no git process in the way)
525 // ═══════════════════════════════════════════════════════════════════════════
526
527 test.skipIf(skipBench)(
528 "bench: raw upload-pack throughput (server capacity, no git CLI)",
529 Effect.gen(function* () {
530 const { url } = yield* stack;
531 const repo = yield* freshRepo(url, "bench", "raw");
532 const tmp = yield* tempDir;
533 const blobKiB = 512 * SCALE;
534
535 yield* mustSh(
536 tmp,
537 `
538 rm -rf work && git -c init.defaultBranch=main clone '${repo.remote}' work
539 cd work
540 head -c ${blobKiB * 1024} /dev/urandom | base64 > payload.txt
541 i=1; while [ $i -le 50 ]; do printf 'f %s\\n' $i > "f$i.txt"; i=$((i+1)); done
542 git add -A && git commit -q -m payload
543 git push -q origin main
544 `,
545 );
546 const head = (yield* mustSh(tmp, `cd work && git rev-parse HEAD`)).stdout;
547 yield* Effect.sleep("6 seconds"); // let the bundle land
548
549 const client = yield* HttpClient.HttpClient;
550 const pkt = (line: string) => `${(line.length + 4).toString(16).padStart(4, "0")}${line}`;
551 const body = `${pkt(`want ${head}\n`)}0000${pkt("done\n")}`;
552
553 /** One full clone over raw HTTP; resolves to bytes received. */
554 const rawClone = client
555 .execute(
556 HttpClientRequest.post(`${url}/bench/raw.git/git-upload-pack`).pipe(
557 HttpClientRequest.setHeaders({
558 authorization: `Bearer ${repo.token}`,
559 "content-type": "application/x-git-upload-pack-request",
560 }),
561 HttpClientRequest.bodyText(body),
562 ),
563 )
564 .pipe(
565 Effect.flatMap((response) => response.arrayBuffer),
566 Effect.map((buffer) => buffer.byteLength),
567 );
568
569 // Warm one request so the measurements exclude cold start.
570 const packBytes = yield* rawClone;
571 expect(packBytes).toBeGreaterThan(1024);
572
573 // The same clone, but with a `have` the server does not know. That
574 // disqualifies the bundle (bundleCovers refuses any request carrying
575 // haves) while producing the SAME pack, so the two lines below are a
576 // like-for-like v1-dynamic vs v2-bundle comparison.
577 const unknownHave = "f".repeat(40);
578 const dynamicClone = client
579 .execute(
580 HttpClientRequest.post(`${url}/bench/raw.git/git-upload-pack`).pipe(
581 HttpClientRequest.setHeaders({
582 authorization: `Bearer ${repo.token}`,
583 "content-type": "application/x-git-upload-pack-request",
584 }),
585 HttpClientRequest.bodyText(
586 `${pkt(`want ${head}\n`)}${pkt(`have ${unknownHave}\n`)}0000${pkt("done\n")}`,
587 ),
588 ),
589 )
590 .pipe(
591 Effect.flatMap((response) => response.arrayBuffer),
592 Effect.map((buffer) => buffer.byteLength),
593 );
594
595 const throughput = (sizes: ReadonlyArray<number>, ms: number, n: number) => {
596 const total = sizes.reduce((sum, bytes) => sum + bytes, 0);
597 return (
598 `${perSecond(n, ms)} clones, ` + `${(total / 1024 / 1024 / (ms / 1000)).toFixed(1)} MiB/s`
599 );
600 };
601
602 for (const concurrency of [1, 8, 32]) {
603 yield* measure(
604 `raw clone x${concurrency} — bundle (${(packBytes / 1024).toFixed(0)} KiB)`,
605 Effect.all(
606 Array.from({ length: concurrency }, () => rawClone),
607 { concurrency },
608 ),
609 (sizes, ms) => throughput(sizes, ms, concurrency),
610 );
611 yield* measure(
612 `raw clone x${concurrency} — dynamic closure walk`,
613 Effect.all(
614 Array.from({ length: concurrency }, () => dynamicClone),
615 { concurrency },
616 ),
617 (sizes, ms) => throughput(sizes, ms, concurrency),
618 );
619 }
620 }).pipe(logLevel),
621 {
622 tags: ["provider:cloudflare", "provider:cloudflare:r2", "provider:cloudflare:worker", "live"],
623 timeout: 900_000,
624 },
625 );
626
627 // ═══════════════════════════════════════════════════════════════════════════
628 // Bottleneck 2 — subrequest limit vs. fragmented packs (DESIGN §15.2)
629 // ═══════════════════════════════════════════════════════════════════════════
630
631 test.skipIf(skipBench)(
632 "bench: dynamic fetch over a compacted repo with >1000 objects",
633 Effect.gen(function* () {
634 const { url } = yield* stack;
635 const repo = yield* freshRepo(url, "bench", "subreq");
636 const tmp = yield* tempDir;
637 // Comfortably past the Workers 1000-subrequest cap once compacted:
638 // one ranged R2 GET per object would fail outright.
639 const files = 1200;
640
641 yield* mustSh(
642 tmp,
643 `
644 rm -rf work && git -c init.defaultBranch=main clone '${repo.remote}' work
645 cd work
646 i=1
647 while [ $i -le ${files} ]; do
648 printf 'payload %s\\n' $i > "f$i.txt"
649 i=$((i+1))
650 done
651 git add -A && git commit -q -m bulk
652 git push -q origin main
653 `,
654 );
655
656 // Force everything into an R2 pack.
657 yield* repo.admin.repos.compact({
658 params: { owner: "bench", repo: "subreq" },
659 });
660 const packed = yield* repo.admin.repos.get({ params: { owner: "bench", repo: "subreq" } }).pipe(
661 Effect.map((found) => found.objects),
662 Effect.repeat({
663 schedule: Schedule.spaced("1 second"),
664 until: (objects: { loose: number; packed: number }) =>
665 objects.packed > 1000 && objects.loose === 0,
666 times: 120,
667 }),
668 );
669 expect(packed.packed).toBeGreaterThan(1000);
670
671 const head = (yield* mustSh(tmp, `cd work && git rev-parse HEAD`)).stdout;
672 const client = yield* HttpClient.HttpClient;
673 const pkt = (line: string) => `${(line.length + 4).toString(16).padStart(4, "0")}${line}`;
674
675 // A `have` the server does not know bypasses the bundle, so this is the
676 // dynamic path reading every object out of the pack.
677 yield* measure(
678 `dynamic fetch, ${packed.packed} packed objects`,
679 client
680 .execute(
681 HttpClientRequest.post(`${url}/bench/subreq.git/git-upload-pack`).pipe(
682 HttpClientRequest.setHeaders({
683 authorization: `Bearer ${repo.token}`,
684 "content-type": "application/x-git-upload-pack-request",
685 }),
686 HttpClientRequest.bodyText(
687 `${pkt(`want ${head}\n`)}${pkt(`have ${"f".repeat(40)}\n`)}0000${pkt("done\n")}`,
688 ),
689 ),
690 )
691 .pipe(
692 Effect.flatMap((response) =>
693 response.arrayBuffer.pipe(
694 Effect.map((buffer) => ({
695 status: response.status,
696 bytes: buffer.byteLength,
697 })),
698 ),
699 ),
700 ),
701 (result, ms) =>
702 `status ${result.status}, ${(result.bytes / 1024).toFixed(0)} KiB in ${(ms / 1000).toFixed(2)}s`,
703 ).pipe(
704 Effect.tap((result) => {
705 // The whole point: this must NOT fail on the subrequest cap.
706 expect(result.status).toBe(200);
707 expect(result.bytes).toBeGreaterThan(10_000);
708 return Effect.void;
709 }),
710 );
711
712 // And the repo still clones cleanly through the same path.
713 yield* mustSh(tmp, `rm -rf verify && git clone -q '${repo.remote}' verify`);
714 yield* mustSh(tmp, `cd verify && git fsck --strict`);
715 }).pipe(logLevel),
716 {
717 tags: ["provider:cloudflare", "provider:cloudflare:r2", "provider:cloudflare:worker", "live"],
718 timeout: 900_000,
719 },
720 );
721
722 // ═══════════════════════════════════════════════════════════════════════════
723 // Bottleneck 1 — push admission. The Repo DO bounds ingest by MEMORY, not
724 // by push count, so a small push no longer waits out a large upload. Both
725 // arms run in ONE case so the comparison is same-repo, same-minute.
726 // ═══════════════════════════════════════════════════════════════════════════
727
728 test.skipIf(skipBench)(
729 "bench: small-push latency alone vs. behind a large upload",
730 Effect.gen(function* () {
731 const { url } = yield* stack;
732 const repo = yield* freshRepo(url, "bench", "admit");
733 const tmp = yield* tempDir;
734 const bigMiB = 12 * SCALE;
735
736 yield* mustSh(
737 tmp,
738 `
739 rm -rf work && git -c init.defaultBranch=main clone '${repo.remote}' work
740 cd work
741 printf 'seed\n' > seed.txt
742 git add -A && git commit -q -m seed
743 git push -q origin main
744 `,
745 );
746
747 /** A one-file push to its own branch — kilobytes of actual work. */
748 const smallPush = (n: number) =>
749 mustSh(
750 tmp,
751 `
752 cd work
753 git checkout -q -B "tiny${n}" main
754 printf 'tiny %s\n' ${n} > "tiny${n}.txt"
755 git add -A && git commit -q -m "tiny${n}"
756 git push -q origin "tiny${n}"
757 git checkout -q main
758 `,
759 );
760
761 // Uncontended baseline.
762 yield* smallPush(1);
763 yield* measure("small push, uncontended", smallPush(2), (_, ms) => `${ms.toFixed(0)} ms`);
764
765 // Now the same push while a large body is still uploading. Under
766 // count-based admission the small push waited for the whole upload;
767 // under a byte budget it only needs its own MiB.
768 yield* mustSh(
769 tmp,
770 `
771 cd work
772 git checkout -q -B heavy main
773 head -c ${bigMiB * 1024 * 1024} /dev/urandom > heavy.bin
774 git add -A && git commit -q -m heavy
775 git checkout -q main
776 `,
777 );
778 // Fork the heavy push so the measurement covers the SMALL push alone,
779 // not the pair — timing both together just reports the heavy one.
780 const heavy = yield* Effect.forkChild(mustSh(tmp, `cd work && git push -q origin heavy`));
781 yield* measure(
782 `small push, while a ${bigMiB} MiB upload is in flight`,
783 smallPush(3),
784 (_, ms) => `${ms.toFixed(0)} ms`,
785 );
786 yield* Fiber.join(heavy);
787 }).pipe(logLevel),
788 {
789 tags: ["provider:cloudflare", "provider:cloudflare:r2", "provider:cloudflare:worker", "live"],
790 timeout: 900_000,
791 },
792 );
793
794 // ═══════════════════════════════════════════════════════════════════════════
795 // Bottleneck 2 — bundle staleness. A ref moving after the bundle was cut
796 // used to drop every clone onto the dynamic closure walk; the bundle is now
797 // spliced with a small delta pack instead. Fresh and stale are measured in
798 // the same run against the same repo.
799 // ═══════════════════════════════════════════════════════════════════════════
800
801 test.skipIf(skipBench)(
802 "bench: clone TPS against a FRESH vs a STALE bundle",
803 Effect.gen(function* () {
804 const { url } = yield* stack;
805 const repo = yield* freshRepo(url, "bench", "stale");
806 const tmp = yield* tempDir;
807 const blobKiB = 512 * SCALE;
808
809 yield* mustSh(
810 tmp,
811 `
812 rm -rf work && git -c init.defaultBranch=main clone '${repo.remote}' work
813 cd work
814 head -c ${blobKiB * 1024} /dev/urandom | base64 > payload.txt
815 i=1; while [ $i -le 50 ]; do printf 'f %s\n' $i > "f$i.txt"; i=$((i+1)); done
816 git add -A && git commit -q -m payload
817 git push -q origin main
818 `,
819 );
820 yield* Effect.sleep("8 seconds"); // let the bundle land
821
822 const client = yield* HttpClient.HttpClient;
823 const pkt = (line: string) => `${(line.length + 4).toString(16).padStart(4, "0")}${line}`;
824 const request = (head: string) =>
825 client.execute(
826 HttpClientRequest.post(`${url}/bench/stale.git/git-upload-pack`).pipe(
827 HttpClientRequest.setHeaders({
828 authorization: `Bearer ${repo.token}`,
829 "content-type": "application/x-git-upload-pack-request",
830 }),
831 HttpClientRequest.bodyText(`${pkt(`want ${head}\n`)}0000${pkt("done\n")}`),
832 ),
833 );
834 const cloneAt = (head: string) =>
835 request(head).pipe(
836 Effect.flatMap((response) => response.arrayBuffer),
837 Effect.map((buffer) => buffer.byteLength),
838 );
839 /** Which plane answered — `do-bundle:bundle`, `…:spliced`, or none. */
840 const planeAt = (head: string) =>
841 request(head).pipe(
842 Effect.map((response) => response.headers["x-git-served-by"] ?? "dynamic"),
843 );
844
845 const N = 32 * SCALE;
846 const throughput = (sizes: ReadonlyArray<number>, ms: number) => {
847 const total = sizes.reduce((sum, bytes) => sum + bytes, 0);
848 return (
849 `${perSecond(sizes.length, ms)} clones, ` +
850 `${(total / 1024 / 1024 / (ms / 1000)).toFixed(1)} MiB/s`
851 );
852 };
853
854 const fresh = (yield* mustSh(tmp, `cd work && git rev-parse HEAD`)).stdout;
855 yield* cloneAt(fresh); // warm
856 const freshPlane = yield* planeAt(fresh);
857 results.push(` fresh arm served by: ${freshPlane}`);
858 yield* measure(
859 `${N} clones, FRESH bundle, concurrency 32`,
860 Effect.all(
861 Array.from({ length: N }, () => cloneAt(fresh)),
862 { concurrency: 32 },
863 ),
864 throughput,
865 );
866
867 // Move main past the bundle and clone immediately: the bundle on disk
868 // no longer names this tip.
869 yield* mustSh(
870 tmp,
871 `
872 cd work
873 printf 'more\n' > more.txt
874 git add -A && git commit -q -m more
875 git push -q origin main
876 `,
877 );
878 const stale = (yield* mustSh(tmp, `cd work && git rev-parse HEAD`)).stdout;
879 const warmStale = yield* cloneAt(stale);
880 expect(warmStale).toBeGreaterThan(1024);
881 const stalePlane = yield* planeAt(stale);
882 results.push(` stale arm served by: ${stalePlane}`);
883 yield* measure(
884 `${N} clones, STALE bundle (dynamic fallback), concurrency 32`,
885 Effect.all(
886 Array.from({ length: N }, () => cloneAt(stale)),
887 { concurrency: 32 },
888 ),
889 throughput,
890 );
891 }).pipe(logLevel),
892 {
893 tags: ["provider:cloudflare", "provider:cloudflare:r2", "provider:cloudflare:worker", "live"],
894 timeout: 900_000,
895 },
896 );
897
898 // ═══════════════════════════════════════════════════════════════════════════
899 // Single large clone — where does the time go? Splits time-to-first-byte
900 // (planning: Worker -> DO -> R2 HEAD -> marker) from transfer (bytes on
901 // the wire), per serving path, on a real ~36 MiB repository. This is the
902 // instrument for "clones feel slow": a large TTFB is planning latency, a
903 // low MiB/s with small TTFB is the streaming path itself.
904 // ═══════════════════════════════════════════════════════════════════════════
905
906 test.skipIf(skipBench)(
907 "bench: single large clone — TTFB vs transfer, by serving path",
908 Effect.gen(function* () {
909 const { url } = yield* stack;
910 const tmp = yield* tempDir;
911
912 // Same source as the real-world suite: this monorepo, depth-1, as one
913 // root commit — ~13.6k objects, ~36 MiB.
914 const root = (yield* mustSh(process.cwd(), `git rev-parse --show-toplevel`)).stdout;
915 yield* mustSh(
916 tmp,
917 `
918 rm -rf src
919 git clone -q --depth 1 "file://${root}" src
920 cd src && rm -rf .git && git init -q -b main && git add -A
921 git commit -q -m "alchemy snapshot"
922 `,
923 );
924 const repo = yield* freshRepo(url, "bench", "large", { public: true });
925 yield* mustSh(
926 tmp,
927 `cd src && git remote add origin '${repo.remote}' && git push -q origin main`,
928 );
929 const head = (yield* mustSh(tmp, `cd src && git rev-parse HEAD`)).stdout;
930
931 const client = yield* HttpClient.HttpClient;
932 const pkt = (line: string) => `${(line.length + 4).toString(16).padStart(4, "0")}${line}`;
933 const request = (body: string) =>
934 client.execute(
935 HttpClientRequest.post(`${url}/bench/large.git/git-upload-pack`).pipe(
936 HttpClientRequest.setHeaders({
937 authorization: `Bearer ${repo.token}`,
938 "content-type": "application/x-git-upload-pack-request",
939 }),
940 HttpClientRequest.bodyText(body),
941 ),
942 );
943 const bodies = {
944 passthrough: `${pkt(`want ${head}\n`)}0000${pkt("done\n")}`,
945 sideband: `${pkt(`want ${head} side-band-64k\n`)}0000${pkt("done\n")}`,
946 dynamic: `${pkt(`want ${head}\n`)}${pkt(`have ${"f".repeat(40)}\n`)}0000${pkt("done\n")}`,
947 };
948
949 /**
950 * One clone, timed in two halves: headers (TTFB) and body drain — and
951 * VERIFIED: the pack is de-framed and its SHA-1 trailer checked. A
952 * stream that aborts mid-body can reach a lenient HTTP client as a
953 * clean end (seen once: 0.5 MiB of a 40.6 MiB pack, test green), so
954 * bytes alone prove nothing.
955 */
956 const timedClone = (body: string) =>
957 Effect.gen(function* () {
958 const t0 = performance.now();
959 const response = yield* request(body);
960 const ttfbMs = performance.now() - t0;
961 const raw = new Uint8Array(yield* response.arrayBuffer);
962 const totalMs = performance.now() - t0;
963 const pack = yield* Effect.sync(() =>
964 verifyPackResponse(raw, body.includes("side-band-64k")),
965 );
966 expect(pack.error, `pack response: ${pack.error}`).toBeUndefined();
967 return {
968 ttfbMs,
969 totalMs,
970 bytes: raw.byteLength,
971 objects: pack.objects,
972 via: response.headers["x-git-served-by"] ?? "dynamic",
973 };
974 });
975 const describe = (r: {
976 ttfbMs: number;
977 totalMs: number;
978 bytes: number;
979 objects: number;
980 via: string;
981 }) =>
982 `ttfb ${r.ttfbMs.toFixed(0)}ms, total ${(r.totalMs / 1000).toFixed(2)}s, ` +
983 `${(r.bytes / 1048576).toFixed(1)} MiB (${r.objects} objects, trailer ok) @ ` +
984 `${(r.bytes / 1048576 / ((r.totalMs - r.ttfbMs) / 1000)).toFixed(1)} MiB/s transfer ` +
985 `[${r.via}]`;
986
987 // Wait for the bundle to land (a 36 MiB cut takes a while), bounded.
988 yield* timedClone(bodies.passthrough).pipe(
989 Effect.repeat({
990 schedule: Schedule.spaced("5 seconds"),
991 until: (r) => r.via.startsWith("do-bundle"),
992 times: 36,
993 }),
994 );
995
996 for (const [name, body] of Object.entries(bodies)) {
997 yield* timedClone(body); // warm
998 yield* measure(`large clone x1 — ${name}`, timedClone(body), (r) => describe(r));
999 }
1000
1001 // Does the streaming path scale with parallel streams, or is it a
1002 // per-stream ceiling? 4 passthrough clones at once.
1003 yield* measure(
1004 "large clone x4 — passthrough, concurrent",
1005 Effect.all(
1006 Array.from({ length: 4 }, () => timedClone(bodies.passthrough)),
1007 { concurrency: 4 },
1008 ),
1009 (rs, ms) => {
1010 const total = rs.reduce((n, r) => n + r.bytes, 0);
1011 return `${(total / 1048576 / (ms / 1000)).toFixed(1)} MiB/s aggregate over ${(ms / 1000).toFixed(2)}s`;
1012 },
1013 );
1014 }).pipe(logLevel),
1015 {
1016 tags: ["provider:cloudflare", "provider:cloudflare:r2", "provider:cloudflare:worker", "live"],
1017 timeout: 1_200_000,
1018 },
1019 );
1020
1021 // ═══════════════════════════════════════════════════════════════════════════
1022 // Bottleneck 8 — the DO on the anonymous read path (Continuity learnings,
1023 // DESIGN.md §21): every advertisement and bundle-planning hop wakes the
1024 // repo DO today, so anonymous public reads share one single-threaded
1025 // object. Baseline for the DO-less head-object fast path.
1026 // ═══════════════════════════════════════════════════════════════════════════
1027
1028 test.skipIf(skipBench)(
1029 "bench: anonymous reads on a PUBLIC repo (advertisement + raw clone TPS)",
1030 Effect.gen(function* () {
1031 const { url } = yield* stack;
1032 const repo = yield* freshRepo(url, "bench", "pubread", { public: true });
1033 const tmp = yield* tempDir;
1034 const blobKiB = 256 * SCALE;
1035
1036 yield* mustSh(
1037 tmp,
1038 `
1039 rm -rf work && git -c init.defaultBranch=main clone '${repo.remote}' work
1040 cd work
1041 head -c ${blobKiB * 1024} /dev/urandom > blob.bin
1042 i=1; while [ $i -le 20 ]; do printf 'f %s\n' $i > "f$i.txt"; i=$((i+1)); done
1043 git add -A && git commit -q -m payload
1044 git push -q origin main
1045 `,
1046 );
1047 const head = (yield* mustSh(tmp, `cd work && git rev-parse HEAD`)).stdout;
1048 yield* Effect.sleep("6 seconds"); // let the bundle land
1049
1050 const client = yield* HttpClient.HttpClient;
1051 const pkt = (line: string) => `${(line.length + 4).toString(16).padStart(4, "0")}${line}`;
1052
1053 // TOKENLESS advertisement — GET info/refs with no Authorization.
1054 const advertise = client.get(`${url}/bench/pubread.git/info/refs?service=git-upload-pack`).pipe(
1055 Effect.flatMap((response) => response.arrayBuffer),
1056 Effect.map((buffer) => buffer.byteLength),
1057 );
1058 // warm + correctness: the advertisement carries the tip AND proves
1059 // the DO-less path served it (not an accidental DO fall-through).
1060 const warmAdv = yield* client.get(`${url}/bench/pubread.git/info/refs?service=git-upload-pack`);
1061 expect(warmAdv.headers["x-git-served-by"]).toBe("head-snapshot");
1062 const advBytes = (yield* warmAdv.arrayBuffer).byteLength;
1063 expect(advBytes).toBeGreaterThan(40);
1064
1065 const SERIAL_N = 20;
1066 yield* measure(
1067 `${SERIAL_N} serial anonymous advertisements`,
1068 Effect.forEach(Array.from({ length: SERIAL_N }), () => advertise),
1069 (_, ms) => `${(ms / SERIAL_N).toFixed(0)} ms each`,
1070 );
1071
1072 const ADV_N = 128 * SCALE;
1073 yield* measure(
1074 `${ADV_N} anonymous advertisements, concurrency 32`,
1075 Effect.all(
1076 Array.from({ length: ADV_N }, () => advertise),
1077 { concurrency: 32 },
1078 ),
1079 (sizes, ms) => `${perSecond(sizes.length, ms)} advertisements`,
1080 );
1081
1082 // TOKENLESS full clone over raw HTTP (want tip, done — bundle-eligible).
1083 const rawClone = client
1084 .execute(
1085 HttpClientRequest.post(`${url}/bench/pubread.git/git-upload-pack`).pipe(
1086 HttpClientRequest.setHeaders({
1087 "content-type": "application/x-git-upload-pack-request",
1088 }),
1089 HttpClientRequest.bodyText(`${pkt(`want ${head}\n`)}0000${pkt("done\n")}`),
1090 ),
1091 )
1092 .pipe(
1093 Effect.flatMap((response) => response.arrayBuffer),
1094 Effect.map((buffer) => buffer.byteLength),
1095 );
1096 // warm + prove the bundle was served DO-lessly from the snapshot
1097 const warmClone = yield* client.execute(
1098 HttpClientRequest.post(`${url}/bench/pubread.git/git-upload-pack`).pipe(
1099 HttpClientRequest.setHeaders({
1100 "content-type": "application/x-git-upload-pack-request",
1101 }),
1102 HttpClientRequest.bodyText(`${pkt(`want ${head}\n`)}0000${pkt("done\n")}`),
1103 ),
1104 );
1105 expect(warmClone.headers["x-git-served-by"]).toBe("head-snapshot:bundle");
1106 const first = (yield* warmClone.arrayBuffer).byteLength;
1107 expect(first).toBeGreaterThan(blobKiB * 1024 * 0.5);
1108
1109 const CLONE_N = 64 * SCALE;
1110 yield* measure(
1111 `${CLONE_N} anonymous raw clones, concurrency 32`,
1112 Effect.all(
1113 Array.from({ length: CLONE_N }, () => rawClone),
1114 { concurrency: 32 },
1115 ),
1116 (sizes, ms) => {
1117 const total = sizes.reduce((sum, bytes) => sum + bytes, 0);
1118 return (
1119 `${perSecond(sizes.length, ms)} clones, ` +
1120 `${(total / 1024 / 1024 / (ms / 1000)).toFixed(1)} MiB/s`
1121 );
1122 },
1123 );
1124
1125 // and a real git clone with NO credentials still works
1126 const parsed = new URL(url);
1127 yield* mustSh(
1128 tmp,
1129 `rm -rf anon && git clone -q '${parsed.protocol}//${parsed.host}/bench/pubread.git' anon && cd anon && git fsck --strict`,
1130 );
1131 }).pipe(logLevel),
1132 {
1133 tags: ["provider:cloudflare", "provider:cloudflare:r2", "provider:cloudflare:worker", "live"],
1134 timeout: 900_000,
1135 },
1136 );
1137
1138 // ═══════════════════════════════════════════════════════════════════════════
1139 // Bottleneck 9 — pack-count growth (Continuity learnings, DESIGN.md §21):
1140 // each compaction run writes a NEW pack and never merges, so reads over an
1141 // old repo fan out across ever more packs. Baseline for geometric merging.
1142 // ═══════════════════════════════════════════════════════════════════════════
1143
1144 test.skipIf(skipBench)(
1145 "bench: dynamic fetch over a repo compacted in 6 increments (pack fan-out)",
1146 Effect.gen(function* () {
1147 const { url } = yield* stack;
1148 const repo = yield* freshRepo(url, "bench", "npack");
1149 const tmp = yield* tempDir;
1150 const ROUNDS = 6;
1151
1152 yield* mustSh(tmp, `rm -rf work && git -c init.defaultBranch=main clone '${repo.remote}' work`);
1153
1154 // ROUNDS x (push a batch, compact it) => ROUNDS separate packs today.
1155 for (let round = 1; round <= ROUNDS; round++) {
1156 yield* mustSh(
1157 tmp,
1158 `
1159 cd work
1160 i=1; while [ $i -le 12 ]; do head -c ${32 * 1024} /dev/urandom > "r${round}-f$i.bin"; i=$((i+1)); done
1161 git add -A && git commit -q -m "round ${round}"
1162 git push -q origin main
1163 `,
1164 );
1165 yield* repo.admin.repos
1166 .compact({ params: { owner: "bench", repo: "npack" } })
1167 .pipe(edgeRetry);
1168 // wait until the loose rows have drained into the pack
1169 yield* repo.admin.repos.get({ params: { owner: "bench", repo: "npack" } }).pipe(
1170 edgeRetry,
1171 Effect.repeat({
1172 schedule: Schedule.spaced("2 seconds"),
1173 until: (meta) => meta.objects.loose === 0,
1174 times: 45,
1175 }),
1176 );
1177 }
1178
1179 const after = yield* repo.admin.repos
1180 .get({ params: { owner: "bench", repo: "npack" } })
1181 .pipe(edgeRetry);
1182 results.push(
1183 `npack repo: ${after.objects.packed} packed objects after ${ROUNDS} compactions`.padEnd(46),
1184 );
1185
1186 const head = (yield* mustSh(tmp, `cd work && git rev-parse HEAD`)).stdout;
1187 const client = yield* HttpClient.HttpClient;
1188 const pkt = (line: string) => `${(line.length + 4).toString(16).padStart(4, "0")}${line}`;
1189
1190 // Unknown have forces the dynamic path (bundle refused): the closure
1191 // walk + object reads must range-read across every pack.
1192 const unknownHave = "f".repeat(40);
1193 const dynamicFetch = client
1194 .execute(
1195 HttpClientRequest.post(`${url}/bench/npack.git/git-upload-pack`).pipe(
1196 HttpClientRequest.setHeaders({
1197 authorization: `Bearer ${repo.token}`,
1198 "content-type": "application/x-git-upload-pack-request",
1199 }),
1200 HttpClientRequest.bodyText(
1201 `${pkt(`want ${head}\n`)}${pkt(`have ${unknownHave}\n`)}0000${pkt("done\n")}`,
1202 ),
1203 ),
1204 )
1205 .pipe(
1206 Effect.flatMap((response) => response.arrayBuffer),
1207 Effect.map((buffer) => buffer.byteLength),
1208 );
1209
1210 const warm = yield* dynamicFetch;
1211 expect(warm).toBeGreaterThan(100_000);
1212
1213 const N = 8;
1214 yield* measure(
1215 `${N} serial dynamic fetches over ${ROUNDS}-increment repo`,
1216 Effect.forEach(Array.from({ length: N }), () => dynamicFetch),
1217 (sizes, ms) =>
1218 `${(ms / N).toFixed(0)} ms/fetch, ` +
1219 `${((sizes[0] ?? 0) / 1024 / 1024).toFixed(1)} MiB pack`,
1220 );
1221
1222 // correctness: clone back clean through the same packs
1223 yield* mustSh(tmp, `rm -rf verify && git clone -q '${repo.remote}' verify`);
1224 yield* mustSh(tmp, `cd verify && git fsck --strict`);
1225 }).pipe(logLevel),
1226 {
1227 tags: ["provider:cloudflare", "provider:cloudflare:r2", "provider:cloudflare:worker", "live"],
1228 timeout: 900_000,
1229 },
1230 );