GitHubivarvong
ply
main
1// One packSubset of a synthetic pack far larger than what is held (test/pack-subset.test.js), under --expose-gc. The
2// source is N copies of one stored-zlib blob entry, served as views of that one entry's bytes, so the source itself
3// holds one entry; the index comes from scanPackIndex over the same bytes. Every other entry is selected and the result
4// drained slowly. The peak is sampled after a full GC every 50 ms. Prints one JSON line.
5// node --expose-gc --import ./test/ts-resolve.mjs test/pack-subset-child.mjs <blob bytes> <entries>
6import { deflateSync } from 'node:zlib';
7import { packSubset } from '../src/packsubset.js';
8import { scanPackIndex } from '../src/packscanindex.js';
9import { encodeObjHeader, packHeader } from '../src/pack.js';
10import { TYPE } from '../src/objects.js';
11import { concat } from '../src/bytes.js';
13const [blobBytes, count] = process.argv.slice(2).map(Number);
14const blob = new Uint8Array(blobBytes);
15for (let i = 0; i < blob.length; i++) blob[i] = (i * 2654435761) >>> 24;
16const entry = concat([encodeObjHeader(TYPE.BLOB, blob.length), new Uint8Array(deflateSync(blob, { level: 0 }))]);
17const head = packHeader(count);
18const trailer = new Uint8Array(20);
19const size = head.length + entry.length * count + trailer.length;
20const CHUNK = 64 * 1024;
21// the bytes at [offset, offset + length) as views of head, entry and trailer
22function* views(offset, length) {
23 let at = offset;
24 const end = offset + length;
25 while (at < end) {
26 let part, from;
27 if (at < head.length) { part = head; from = at; } else if (at >= size - trailer.length) { part = trailer; from = at - (size - trailer.length); } else { part = entry; from = (at - head.length) % entry.length; }
28 const n = Math.min(end - at, part.length - from, CHUNK);
29 yield part.subarray(from, from + n);
30 at += n;
31 }
32}
33const streamOf = (offset, length) => {
34 const it = views(offset, length);
35 return new ReadableStream({ pull(c) { const r = it.next(); if (r.done) c.close(); else c.enqueue(r.value); } }, { highWaterMark: 0 });
36};
37const source = { size, read: async (offset, length) => ({ ok: true, value: streamOf(offset, length) }) };
38const scanned = await scanPackIndex(streamOf(0, size), { verify: false, oids: false });
39if (!scanned.ok) { process.stdout.write(`${JSON.stringify({ ok: false, error: scanned.error.message })}\n`); process.exit(0); }
40const idx = scanned.value;
41const selection = [...Array(count).keys()].filter(i => i % 2 === 0);
42globalThis.gc(); globalThis.gc();
43const base = process.memoryUsage();
44let peak = base.arrayBuffers, samples = 0;
45const timer = setInterval(() => { globalThis.gc(); samples++; peak = Math.max(peak, process.memoryUsage().arrayBuffers); }, 50);
46const t0 = performance.now();
47const built = await packSubset(source, idx, selection);
48let sent = 0, error = null;
49if (built.ok) {
50 const reader = built.value.stream.getReader();
51 try {
52 for (let k = 0; ; k++) {
53 const r = await reader.read();
54 if (r.done) break;
55 sent += r.value.length;
56 if (k % 64 === 0) await new Promise(resolve => setTimeout(resolve, 1));
57 }
58 } catch (e) { error = e.message; }
59}
60const ms = performance.now() - t0;
61clearInterval(timer);
62process.stdout.write(`${JSON.stringify({
63 ok: built.ok && error === null, error: built.ok ? error : built.error.message, sourceBytes: size, length: built.ok ? built.value.length : null,
64 sent, ms: Math.round(ms), mbPerS: Math.round(sent / 1e6 / (ms / 1000)), samples, liveDelta: peak - base.arrayBuffers,
65})}\n`);
Diagnostics6 git calls · 27 ms
CallStatusSizeTime027 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 KiB · hit3 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=11990 git.response.cache=HIT git.response.duration_ms=3 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 · 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=919 git.response.cache=HIT git.response.duration_ms=2 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 · hit1 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=1 git.response.bytes=5724 git.response.cache=HIT git.response.duration_ms=1 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
fetch2001.6 KiB · hit18 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=18 git.response.bytes=1625 git.response.cache=HIT git.response.duration_ms=18 git.fetch.wants=61db9d2812041d73a70c897bc308e8b86161b98e 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=1625 git.pkt.payload.max=1598 git.sideband.band1.bytes=1598 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
- a5e1c7b80a65c6f8
- Request
- dbb92db8…
- 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