GitHubivarvong

ply

main
ply6 git calls168 ms21 KiB3 cachedprotocol v2
72 lines4.4 KiBRaw
1// Delta instructions, encoded (gitformat-pack "Deltified representation"): the size varint, copy and insert opcodes, a
2// delta from its instructions, and the structural splice the edit pipeline sends. A leaf: pack.ts (the pack builder)
3// and packresolve.ts (makeDelta) both import it, and it imports neither.
4import { concat } from './bytes.js';
5import {
6 BYTE_MASK, OBJ_SIZE_NEXT_MASK, OBJ_CONTINUE, OBJ_SIZE_NEXT_BASE,
7 DELTA_COPY, DELTA_COPY_MAX, DELTA_INSERT_MAX, DELTA_OFF_SHIFT,
8 DELTA_COPY_OFF1, DELTA_COPY_OFF2, DELTA_COPY_OFF3, DELTA_COPY_OFF4,
9 DELTA_COPY_LEN1, DELTA_COPY_LEN2, DELTA_COPY_LEN3,
10} from './format.js';
12export function encodeVarint(n: number): Uint8Array { // delta header style: 7-bit LE groups
13 const out: number[] = [];
14 let rest = n;
15 do { let b = rest & OBJ_SIZE_NEXT_MASK; rest = Math.floor(rest / OBJ_SIZE_NEXT_BASE); if (rest > 0) b |= OBJ_CONTINUE; out.push(b); } while (rest > 0);
16 return Uint8Array.from(out);
18export const copyOp = (off: number, len: number): Uint8Array => {
19 let op = DELTA_COPY;
20 const b: number[] = [];
21 let o = off;
22 let l = len === DELTA_COPY_MAX ? 0 : len;
23 if (o & BYTE_MASK) { op |= DELTA_COPY_OFF1; b.push(o & BYTE_MASK); } o >>>= DELTA_OFF_SHIFT;
24 if (o & BYTE_MASK) { op |= DELTA_COPY_OFF2; b.push(o & BYTE_MASK); } o >>>= DELTA_OFF_SHIFT;
25 if (o & BYTE_MASK) { op |= DELTA_COPY_OFF3; b.push(o & BYTE_MASK); } o >>>= DELTA_OFF_SHIFT;
26 if (o & BYTE_MASK) { op |= DELTA_COPY_OFF4; b.push(o & BYTE_MASK); }
27 if (l & BYTE_MASK) { op |= DELTA_COPY_LEN1; b.push(l & BYTE_MASK); } l >>>= DELTA_OFF_SHIFT;
28 if (l & BYTE_MASK) { op |= DELTA_COPY_LEN2; b.push(l & BYTE_MASK); } l >>>= DELTA_OFF_SHIFT;
29 if (l & BYTE_MASK) { op |= DELTA_COPY_LEN3; b.push(l & BYTE_MASK); }
30 return Uint8Array.of(op, ...b);
31};
32export const copyOps = (off: number, len: number): Uint8Array[] => {
33 const parts: Uint8Array[] = [];
34 let o = off;
35 let left = len;
36 while (left > 0) { const n = Math.min(left, DELTA_COPY_MAX); parts.push(copyOp(o, n)); o += n; left -= n; }
37 return parts;
38};
39export const insertOps = (bytes: Uint8Array): Uint8Array[] => {
40 const parts: Uint8Array[] = [];
41 for (let i = 0; i < bytes.length; i += DELTA_INSERT_MAX) {
42 const chunk = bytes.subarray(i, Math.min(i + DELTA_INSERT_MAX, bytes.length));
43 parts.push(Uint8Array.of(chunk.length), chunk);
44 }
45 return parts;
46};
48// One delta instruction (gitformat-pack "Deltified representation"): copy `len` bytes of the source from `off`, or insert
49// the literal bytes. A copy longer than DELTA_COPY_MAX or an insert longer than DELTA_INSERT_MAX is one instruction
50// here and as many opcodes as it takes on the wire (encodeDeltaOps).
51export type DeltaOp = { readonly tag: 'copy'; readonly off: number; readonly len: number } | { readonly tag: 'insert'; readonly bytes: Uint8Array };
52// A delta's bytes from its sizes and instructions.
53export function encodeDeltaOps(srcSize: number, dstSize: number, ops: readonly DeltaOp[]): Uint8Array<ArrayBuffer> {
54 const parts = [encodeVarint(srcSize), encodeVarint(dstSize)];
55 for (const op of ops) parts.push(...(op.tag === 'copy' ? copyOps(op.off, op.len) : insertOps(op.bytes)));
56 return concat(parts);
59// Structural delta: base with [off, off+oldLen) replaced by `insert`. Pure; needs no base bytes. The instructions are a
60// copy of the prefix, the insert, and a copy of the tail, each only when it is not empty.
61export type Splice = { readonly baseLen: number; readonly off: number; readonly oldLen: number; readonly insert: Uint8Array };
62export type SplicedDelta = { readonly delta: Uint8Array<ArrayBuffer>; readonly resultLen: number; readonly ops: { readonly copy: number; readonly insert: number }; readonly program: readonly DeltaOp[] };
63export function spliceDelta({ baseLen, off, oldLen, insert }: Splice): SplicedDelta {
64 const resultLen = baseLen - oldLen + insert.length;
65 const tail = baseLen - off - oldLen;
66 const program: DeltaOp[] = [];
67 if (off > 0) program.push({ tag: 'copy', off: 0, len: off });
68 if (insert.length > 0) program.push({ tag: 'insert', bytes: insert });
69 if (tail > 0) program.push({ tag: 'copy', off: off + oldLen, len: tail });
70 // Stryker disable next-line EqualityOperator,ConditionalExpression: an empty prefix or tail is Math.ceil(0) = 0 copies either way
71 return { delta: encodeDeltaOps(baseLen, resultLen, program), resultLen, program, ops: { copy: (off > 0 ? Math.ceil(off / DELTA_COPY_MAX) : 0) + (tail > 0 ? Math.ceil(tail / DELTA_COPY_MAX) : 0), insert: Math.ceil(insert.length / DELTA_INSERT_MAX) } };
Diagnostics6 git calls · 168 ms
CallStatusSizeTime0168 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 KiB2 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=UPDATING
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 · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=4347
git.response.cache=HIT
git.response.duration_ms=4
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: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:02002.4 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=2507
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=8f720d29ff85ce682ffdad9c393b04a3834c3203
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=2507
git.pkt.payload.max=2480
git.sideband.band1.bytes=2480
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=2480
git.pack.trailer=723b6bf1d4d6021fe5eb940c622b9ff00ee4a381
Open pack map
fetch2001.6 KiB156 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=156
git.response.bytes=1605
git.response.cache=MISS
git.response.duration_ms=156
git.fetch.wants=344c19f04fff798075ca4f794525b2b66f99e1a2
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=1605
git.pkt.payload.max=1578
git.sideband.band1.bytes=1578
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
a5e2ddad88b82308
Request
1769323a…
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