Artifactspublic-v0

ply

main
ply4 git calls21 ms40 KiB3 cachedprotocol v2
66 lines4.5 KiBRaw
1// Demo: one edit against the 10 GB / 1000-commit repo, narrated from the OTLP spans, then verified by git.
2// node test/demo.mjs [--dir /tmp/bigrepo]
3import { execFileSync } from 'node:child_process';
4import { join } from 'node:path';
5import { statSync, readdirSync } from 'node:fs';
6import { startGitServer } from './server.js';
7import { editFile } from '../src/edit.js';
8import { Tracer, arrayExporter, flattenLine } from '../src/otel.js';
9import { unwrapAsync } from './unwrap.js';
11const DIR = process.argv.includes('--dir') ? process.argv[process.argv.indexOf('--dir') + 1] : '/tmp/bigrepo';
12const bare = join(DIR, 'big.git');
13const git = a => execFileSync('git', ['-C', bare, ...a], { encoding: 'utf8', maxBuffer: 1 << 30 }).trim();
14const du = d => readdirSync(d, { withFileTypes: true }).reduce((n, e) => n + (e.isDirectory() ? du(join(d, e.name)) : statSync(join(d, e.name)).size), 0);
15const fmt = n => n >= 2 ** 30 ? `${(n / 2 ** 30).toFixed(2)} GB` : n >= 2 ** 20 ? `${(n / 2 ** 20).toFixed(1)} MB` : n >= 1024 ? `${(n / 1024).toFixed(1)} KB` : `${n} B`;
16const W = 70;
17const line = (l, r = '') => console.log(' ' + l.padEnd(W - r.length) + r);
18const hr = () => console.log(' ' + '─'.repeat(W));
20const head = git(['rev-parse', 'main']);
21const headBytes = git(['ls-tree', '-r', '-l', 'main']).split('\n').reduce((n, l) => n + (+l.split(/\s+/)[3] || 0), 0);
22const rev = Math.floor((+git(['rev-list', '--count', 'main']) - 1) / 50) * 50;
23const PATH = 'src/mod17/file9.ts', FIND = `MARK_${rev}`, REPLACE = `EDITED_${rev}`;
25console.log();
26line('REPO', git(['rev-list', '--count', 'main']) + ' commits');
27line(' on disk', fmt(du(join(bare, 'objects/pack'))) + ' (packed, bitmap + multi-pack-index)');
28line(' at HEAD', `${fmt(headBytes)} in ${git(['ls-tree', '-r', 'main']).split('\n').length} files`);
29line(' HEAD', head);
30console.log();
31line('EDIT', `${PATH}: "${FIND}" → "${REPLACE}"`);
32hr();
34const srv = await startGitServer(DIR);
35const exporter = arrayExporter();
36const t0 = Date.now();
37const r = await unwrapAsync(editFile(`${srv.url}/big.git`, { path: PATH, find: FIND, replace: REPLACE, author: { name: 'demo', email: 'demo@edge' }, message: 'demo edit' }, { tracer: new Tracer({ exporter }), verify: true }));
38const wall = Date.now() - t0;
39await srv.close();
40const spans = exporter.lines.flatMap(flattenLine);
42let totalIn = 0, totalOut = 0, n = 0;
43for (const s of spans.filter(s => /upload-pack|receive-pack/.test(s.name)).sort((a, b) => a.start - b.start)) {
44 const a = s.attrs; const inB = a['http.response.body.size'] ?? 0, outB = a['http.request.body.size'] ?? 0; totalIn += inB; totalOut += outB;
45 const what = s.name.includes('ls-refs') ? `ls-refs ${a['git.ls_refs.prefixes']?.[0] ?? ''}` : s.name.includes('receive') ? `push ${a['git.push.pack.objects']} objects (commit + ${a['git.push.pack.objects'] - 2} tree deltas + blob delta), thin` : `fetch want ${(a['git.fetch.wants']?.[0] ?? '').slice(0, 12)}… ${a['git.fetch.filter'] ? 'filter=' + a['git.fetch.filter'] : ''} ${a['git.fetch.deepen'] ? 'deepen=' + a['git.fetch.deepen'] : ''} → ${a['git.pack.objects'] ?? 1} object${a['git.pack.inflated.bytes'] ? ', ' + fmt(a['git.pack.inflated.bytes']) + ' inflated' : ''}`;
46 line(`${++n}. ${what}`, `${String(outB).padStart(5)} B out ${String(inB).padStart(6)} B in ${String(Math.round(s.durationMs)).padStart(4)} ms`);
48hr();
49const root = spans.find(s => s.name === 'git.edit');
50line('TOTAL', `${totalOut} B out ${totalIn} B in ${wall} ms`);
51line(' peak single allocation', fmt(root.attrs['mem.alloc.max_single']));
52line(' bytes allocated, whole edit', fmt(root.attrs['mem.alloc.bytes']));
53line(' blob', `${fmt(r.baseLen)} streamed, never held; delta: 3 ops`);
54line(' vs. git clone --depth 1 of the same HEAD', '≈ 13.3 MB in');
55line(' vs. textbook blobless (blob:none)', '≈ 28 KB in');
56console.log();
57line('RESULT', `commit ${r.newCommit.slice(0, 12)} (parent ${r.oldCommit.slice(0, 12)}), verified by re-reading the ref`);
58hr();
59line('git says:');
60line(` rev-parse main`, git(['rev-parse', 'main']) === r.newCommit ? '== our commit' : 'MISMATCH');
61line(` diff --stat ${r.oldCommit.slice(0, 7)}..main`, git(['diff', '--shortstat', r.oldCommit, 'main']));
62line(` grep ${REPLACE} main:${PATH}`, git(['grep', '-c', REPLACE, 'main', '--', PATH]).split(':').pop() + ' match');
63line(` fsck --strict --connectivity-only`, git(['fsck', '--strict', '--connectivity-only', '--no-dangling']) || 'clean');
64line(` log -1 --format=%an/%s`, git(['log', '-1', '--format=%an / %s', 'main']));
65console.log();
66git(['update-ref', 'refs/heads/main', head]); // leave the repo as we found it
Diagnostics4 git calls · 21 ms
CallStatusSizeTime021 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200145 B · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=145
git.pkt.payload.max=76
git.ls_refs.count=2
git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020038 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=16
git.response.bytes=38434
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=19912563f540228593df0c489082e5e2508e21e4
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=6
git.pkt.data=4
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=38434
git.pkt.payload.max=38339
git.sideband.band1.bytes=38338
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=63
git.pack.bytes=38338
git.pack.ofs_delta=0
git.pack.ref_delta=8
git.pack.chain.max=8
git.pack.trailer=0bc36ab7adf82d3109177f11f1ea93f1ce071f77
git.pack.full=55
Open pack map
fetch2002.1 KiB · hit16 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=2153
git.response.cache=HIT
git.response.duration_ms=16
git.fetch.wants=4523614ca074012472003230f2f09f749ec6c66b
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=2153
git.pkt.payload.max=2132
git.sideband.band1.bytes=2131
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply.git
Ref
refs/heads/main
Commit
19912563f540228593df0c489082e5e2508e21e4
cf-ray
a5e2f21c5b4efda9
Request
ad4d39bc…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format