GitHubivarvong

ply

main
ply9 git calls142 ms25 KiB6 cachedprotocol v2
124 lines5.4 KiBRaw
1// Input sources for the memory cells (test/stream/cell.mjs), as plain iterator objects instead of generators (#249).
2//
3// A suspended generator on node 22 (V8 12.4) keeps every register of its frame, so the piece it yielded last, and the
4// `{ value }` of an inner for-of, stay reachable after the consumer dropped them. A heap snapshot at the peak of the
5// scan-work cell found three such 16 KiB pieces retained by the `parameters_and_registers` of `sealed`, `body` and
6// `storedMember` (49,152 B: node 22's whole overage over node 24 there); node 24 (V8 13.6) keeps none. These sources
7// keep only their position between calls, so a cell measures the same bytes on both: the piece being fed is the
8// caller's, and nothing older is reachable from the source.
9//
10// Each source is an iterator (and iterable) over Uint8Array pieces; `step` returns the next piece or END.
11import crypto from 'node:crypto';
13export const END = Symbol('end');
14const DONE = Object.freeze({ done: true, value: undefined });
16export function source(step) {
17 return {
18 next() { const v = step(); return v === END ? DONE : { done: false, value: v }; },
19 [Symbol.iterator]() { return this; },
20 };
22// The same source as an AsyncIterable, without an async frame of its own to hold a piece.
23export function asAsync(src) {
24 return { [Symbol.asyncIterator]() { return { next: () => Promise.resolve(src.next()) }; } };
26// One piece, dropped once it is handed over.
27export const once = piece => { let held = [piece]; return source(() => { const out = held.length > 0 ? held[0] : END; held = []; return out; }); };
28// The sources made by `makers`, one after another; only the current one is held.
29export function seq(makers) {
30 let i = 0, cur = makers.length > 0 ? makers[0]() : once(new Uint8Array(0));
31 return source(() => {
32 for (;;) {
33 const n = cur.next();
34 if (!n.done) return n.value;
35 i += 1;
36 if (i >= makers.length) return END;
37 cur = makers[i]();
38 }
39 });
41// `count` sources from `make(i)`, one after another.
42export function repeat(count, make) {
43 let i = 0, cur = null;
44 return source(() => {
45 for (;;) {
46 if (cur !== null) { const n = cur.next(); if (!n.done) return n.value; cur = null; }
47 if (i >= count) return END;
48 cur = make(i);
49 i += 1;
50 }
51 });
53// The pieces of `src`, then the SHA-1 of them (a pack trailer).
54export function sealed(src) {
55 const sha = crypto.createHash('sha1');
56 let open = true;
57 return source(() => {
58 if (!open) return END;
59 const n = src.next();
60 if (!n.done) { sha.update(n.value); return n.value; }
61 open = false;
62 return new Uint8Array(sha.digest());
63 });
65// `src` regrouped into `size`-byte chunks, as a transport hands a body over. The chunk being filled is held here
66// until it is full: one chunk, by design.
67export function chunked(src, size) {
68 let piece = null, off = 0, ended = false;
69 return source(() => {
70 if (ended) return END;
71 const buf = new Uint8Array(size);
72 let at = 0;
73 while (at < size) {
74 if (piece === null || off === piece.length) {
75 const n = src.next();
76 if (n.done) { ended = true; piece = null; return at > 0 ? buf.subarray(0, at) : END; }
77 piece = n.value; off = 0;
78 }
79 const k = Math.min(size - at, piece.length - off);
80 buf.set(piece.subarray(off, off + k), at);
81 at += k; off += k;
82 }
83 if (off === piece.length) piece = null;
84 return buf;
85 });
87// `src` framed into band-1 pkt-lines of `room` payload bytes, after a `packfile` line and before a flush: a v2 fetch
88// response as it is read. Holds the unframed remainder (under one frame).
89export function framed(src, room) {
90 const te = new TextEncoder();
91 const frame = payload => { const f = new Uint8Array(4 + payload.length); f.set(te.encode((payload.length + 4).toString(16).padStart(4, '0'))); f.set(payload, 4); return f; };
92 let state = 'head', pending = new Uint8Array(0);
93 const band1 = bytes => { const p = new Uint8Array(1 + bytes.length); p[0] = 1; p.set(bytes, 1); return frame(p); };
94 return source(() => {
95 for (;;) {
96 switch (state) {
97 case 'head': state = 'body'; return frame(te.encode('packfile\n'));
98 case 'body': {
99 if (pending.length >= room) { const out = band1(pending.subarray(0, room)); pending = pending.slice(room); return out; }
100 const n = src.next();
101 if (n.done) { state = 'tail'; continue; }
102 const joined = new Uint8Array(pending.length + n.value.length);
103 joined.set(pending); joined.set(n.value, pending.length);
104 pending = joined;
105 continue;
106 }
107 case 'tail': { state = 'flush'; if (pending.length === 0) continue; const out = band1(pending); pending = new Uint8Array(0); return out; }
108 case 'flush': state = 'end'; return te.encode('0000');
109 default: return END;
110 }
111 }
112 });
114// Read `stream` to its end, handing each item to `each`, from read callbacks rather than an async function: a `for
115// await` loop's frame keeps the item before the current one in a register while it waits for the next (a heap snapshot
116// of the pkt-iter cell found one 65,516 B frame held so on node 24 too), and that is the consumer's memory, not the
117// adapter's under test.
118export function drain(stream, each) {
119 const reader = stream.getReader();
120 return new Promise((resolve, reject) => {
121 const step = () => reader.read().then(r => { if (r.done) { resolve(); return; } each(r.value); step(); }, reject);
122 step();
123 });
Diagnostics9 git calls · 142 ms
CallStatusSizeTime0142 ms
discover200191 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=1
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 · 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=11990
git.response.cache=HIT
git.response.duration_ms=2
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 · hit1 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=13
git.response.bytes=4347
git.response.cache=HIT
git.response.duration_ms=1
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=10
Open pack map
fetchtree:0 · deepen 1200347 B · 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=347
git.response.cache=HIT
git.response.duration_ms=1
git.fetch.filter=tree:0
git.fetch.wants=19912563f540228593df0c489082e5e2508e21e4
git.fetch.haves.count=0
git.fetch.deepen=1
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=347
git.pkt.payload.max=247
git.sideband.band1.bytes=247
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=247
git.pack.trailer=4b72f39b5ea57c5ae3009f90b53e3a6a155093e7
Open pack map
fetchcombine:blob:none+tree:2 · deepen 1429—13 ms
git.upload-pack fetch
http.response.status_code=429
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.cache=BYPASS
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=19912563f540228593df0c489082e5e2508e21e4
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
error.type=rate_limited
error=HTTP 429 git-upload-pack: \u000d
<html>\u000d
  <head>\u000d
    <meta content="origin" name="referrer">\u000d
    <title>Rate limit &middot; GitHub</title>\u000d
    <meta name="v
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=5323b9266eea5ded637285d1c5320699f12be76e
Open 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=3
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=be7e0453974a5fe832f9065a33bb7e3434c10e9b
Open pack map
fetchtree:0200200 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=119
git.response.bytes=200
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=c11435e6c34918566bcdf8c5d918e6efddabe286
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=200
git.pkt.payload.max=173
git.sideband.band1.bytes=173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=173
git.pack.trailer=376de41e92a6f5aaa8754d045db726dc04c5ef3a
Open pack map
fetch2002.2 KiB119 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=2259
git.response.cache=MISS
git.response.duration_ms=119
git.fetch.wants=aa3c848c26e3ad3beeda085ecd694b57b35a8b0d
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=2259
git.pkt.payload.max=2232
git.sideband.band1.bytes=2232
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
a5e1c319ebb036cd
Request
fc51a004…
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