main
1// Honest history under both presets (owner decision 1 of the resolve work ceiling): this repository's own pack, built
2// read-only by `git pack-objects --revs --stdout` from HEAD, resolves under DEFAULT_LIMITS and under WORKER_LIMITS, and
3// every object's oid, type and size is what `git index-pack` + `git verify-pack -v` say of the same bytes.
4//
5// Measured on fbbf5d2 (node 24, git 2.50.0), work = bytes inflated + delta results made, the same under both presets:
6// this repository, HEAD history (this test) 3,872 objects (2,985 deltas), 3,307,891 pack bytes, work 69,665,726
7// this repository, every ref (the reviewer's) 7,541 objects, 7,852,523 pack bytes, work 109,854,403
8// an 18 MB pack of this repository, the largest real pack in the session scratch (a clone's own packfile, mostly
9// whole objects) 3,500 objects, 18,028,461 pack bytes, work 4,734,753
10// all ok under both presets, against ceilings of 2,147,483,648 (DEFAULT_LIMITS.maxResolveWork) and 536,870,912
11// (WORKER_LIMITS.maxResolveWork). No clone of git.git or another larger real repository was at hand, so nothing larger
12// was measured. Work counts what resolving reads back: deltas and the bases they rest on, not whole objects nothing
13// rests on, so it is at least the bytes of the objects git stored as deltas (62,663,356 here).
14// A shallow checkout packs less; the oracle is git on the same bytes, so the test holds for whatever HEAD reaches.
15import { test } from 'vitest';
16import assert from 'node:assert/strict';
17import { execFileSync } from 'node:child_process';
18import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
19import { join } from 'node:path';
20import { tmpdir } from 'node:os';
21import { scanPackIndex } from '../src/packscanindex.js';
22import { resolvePackRange } from '../src/packrangeresolve.js';
23import { rangeFromBytes } from '../src/rangesource.js';
24import { DEFAULT_LIMITS, WORKER_LIMITS } from '../src/limits.js';
26const TYPE = { commit: 1, tree: 2, blob: 3, tag: 4 };
27const streamOf = bytes => new ReadableStream({ start(c) { c.enqueue(bytes); c.close(); } });
29test('this repository\'s own history resolves under DEFAULT_LIMITS and WORKER_LIMITS to the objects git finds in the same pack', { timeout: 600_000 }, async () => {
30 const pack = new Uint8Array(execFileSync('git', ['pack-objects', '--revs', '--stdout', '--delta-base-offset', '-q'], { input: 'HEAD\n', maxBuffer: 1 << 30 }));
31 const dir = mkdtempSync(join(tmpdir(), 'ply-resolve-honest-'));
32 let inPack;
33 try {
34 writeFileSync(join(dir, 'p.pack'), pack);
35 execFileSync('git', ['index-pack', '-o', join(dir, 'p.idx'), join(dir, 'p.pack')]);
36 const listing = execFileSync('git', ['verify-pack', '-v', join(dir, 'p.idx')], { encoding: 'utf8', maxBuffer: 1 << 30 });
37 // "<oid> <type> <size> <bytes in pack> <offset> [<depth> <base>]": one line per object, the last two on a delta.
38 // The size there is the delta's own, so each object's size is asked of the repository below.
39 inPack = [...listing.matchAll(/^([0-9a-f]{40}) (?:commit|tree|blob|tag) +\d+ \d+ \d+( \d+ [0-9a-f]{40})?$/gmu)].map(m => ({ oid: m[1], delta: m[2] !== undefined }));
40 } finally { rmSync(dir, { recursive: true, force: true }); }
41 assert.equal(inPack.length, new DataView(pack.buffer, pack.byteOffset).getUint32(8), 'git listed every object the pack header counts');
42 const sized = execFileSync('git', ['cat-file', '--batch-check=%(objectname) %(objecttype) %(objectsize)'], { input: `${inPack.map(o => o.oid).join('\n')}\n`, encoding: 'utf8', maxBuffer: 1 << 30 }).trim().split('\n');
43 const want = sized.map(line => { const [oid, type, size] = line.split(' '); return { oid, type: TYPE[type], size: Number(size) }; });
44 assert.equal(want.length, inPack.length);
45 const key = o => `${o.oid} ${o.type} ${o.size}`;
46 const wantKeys = want.map(key).sort();
47 // every delta's result is made at least once, so the work is at least the bytes of the objects git stored as deltas
48 const deltaBytes = want.reduce((a, o, i) => a + (inPack[i].delta ? o.size : 0), 0);
49 for (const [name, limits] of [['DEFAULT_LIMITS', DEFAULT_LIMITS], ['WORKER_LIMITS', WORKER_LIMITS]]) {
50 const idx = await scanPackIndex(streamOf(pack), { limits });
51 assert.equal(idx.ok, true, idx.ok ? '' : `${name} scan: ${idx.error.message}`);
52 const r = await resolvePackRange(idx.value, rangeFromBytes(pack), { limits });
53 assert.equal(r.ok, true, r.ok ? '' : `${name}: ${r.error.code}: ${r.error.message}`);
54 const got = Array.from({ length: r.value.count }, (_, i) => key({ oid: r.value.oid(i).value, type: r.value.type(i).value, size: r.value.columns.size[i] }));
55 assert.deepEqual(got.sort(), wantKeys, `${name}: oid, type and size of every object`);
56 assert.ok(r.value.stats.work >= deltaBytes, `${name}: work ${r.value.stats.work} under the ${deltaBytes} bytes of deltified objects`);
57 assert.ok(r.value.stats.work <= limits.maxResolveWork, `${name}: work ${r.value.stats.work} past the ceiling`);
58 console.log(JSON.stringify({ preset: name, objects: r.value.count, packBytes: pack.length, deltas: inPack.filter(o => o.delta).length, deltaBytes, work: r.value.stats.work, workMax: r.value.stats.workMax, ceiling: limits.maxResolveWork }));
59 }
60});
Diagnostics4 git calls · 702 ms
CallStatusSizeTime0702 ms
discover200152 B17 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 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 · 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=3 git.response.bytes=145 git.response.cache=HIT git.response.duration_ms=3 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 · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=682 git.response.bytes=38434 git.response.cache=HIT git.response.duration_ms=3 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=55Open pack map
fetch2002.2 KiB682 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2290 git.response.cache=MISS git.response.duration_ms=682 git.fetch.wants=74dbc563ef228656322c264344cdd649bffebdf3 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=2290 git.pkt.payload.max=2269 git.sideband.band1.bytes=2268 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
- a5e30683a93015db
- Request
- 9bf87c59…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format