GitHubivarvong
ply
main
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`);
47}
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
Diagnostics6 git calls · 152 ms
CallStatusSizeTime0152 ms
discover200191 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=191 git.server.agent=git/github-9922ec520325-Linux git.server.object_format=sha1 git.server.caps=agent ls-refs fetch server-option object-format git.server.fetch=shallow wait-for-done filter git.protocol.version=2 git.pkt.frames=9 git.pkt.data=7 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=191 git.pkt.payload.max=36
ls-refs20012 KiB95 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=94 git.response.bytes=11990 git.response.cache=EXPIRED git.response.duration_ms=95 git.protocol.version=2 git.pkt.frames=152 git.pkt.data=151 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=11990 git.pkt.payload.max=122 git.ls_refs.count=151 git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 102004.2 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=4347 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 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=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=4347 git.pkt.payload.max=4247 git.sideband.band1.bytes=4247 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=10 git.pack.bytes=4247 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=a6caf8e129bea82c9bae4cbc7c130c9205add400 git.pack.full=10Open pack map
fetchtree:0200919 B · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=919 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=800d30ba8923860bfc460ca884b7f9ba22083588 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=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=919 git.pkt.payload.max=892 git.sideband.band1.bytes=892 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=892 git.pack.trailer=5323b9266eea5ded637285d1c5320699f12be76eOpen pack map
fetchtree:02005.6 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=5724 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=58fabb6768b3f737ee9cd8bac647bdc27405fb4d 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=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=5724 git.pkt.payload.max=5697 git.sideband.band1.bytes=5697 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=5697 git.pack.trailer=be7e0453974a5fe832f9065a33bb7e3434c10e9bOpen pack map
fetch2002.1 KiB · hit49 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=48 git.response.bytes=2158 git.response.cache=HIT git.response.duration_ms=49 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=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2158 git.pkt.payload.max=2131 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://github.com/ivarvong/ply
- Ref
- refs/heads/main
- Commit
- 19912563f540228593df0c489082e5e2508e21e4
- cf-ray
- a5e2d2e839e2cf3a
- Request
- e0c84c25…
- Protocol
- v2 · sha1
- Agent
- git/github-9922ec520325-Linux
- Filter
- advertised
- Fetch
- shallow wait-for-done filter
- Capabilities
- agent ls-refs fetch server-option object-format