GitHubivarvong

ply

main
ply6 git calls191 ms24 KiB4 cachedprotocol v2
45 lines3.2 KiBRaw
1// readConfig drops a `#` or `;` comment from each line of a stored .git/config in time linear in the line.
2//
3// The oracle for WHAT is dropped is the pattern main (ec337c5) applied, `/[#;].*$/u`, run here by the regex engine on
4// short lines where its cost does not matter: the comment starts at the first `#` or `;` that has no LF, CR, U+2028 or
5// U+2029 after it (`.` stops at those, and `$` without the m flag is only the end of the line). The oracle for the COST
6// is a ratio of two times measured the same way, never a time.
7import { test } from 'vitest';
8import assert from 'node:assert/strict';
9import { configCommentStart } from '../src/transport.js';
10import { readConfig } from '../src/repo-node.js';
12test('configCommentStart cuts exactly where main\'s pattern cut, for every line of up to 5 characters over an 8-letter alphabet', () => {
13 const alphabet = ['a', ' ', '#', ';', '\n', '\r', '\u2028', '\u2029'];
14 let checked = 0;
15 const walk = (line, left) => {
16 assert.equal(line.slice(0, configCommentStart(line)), line.replace(/[#;].*$/u, ''), JSON.stringify(line));
17 checked += 1;
18 if (left > 0) for (const c of alphabet) walk(line + c, left - 1);
19 };
20 walk('', 5);
21 assert.equal(checked, (8 ** 6 - 1) / 7); // 1 + 8 + ... + 8^5 lines: the walk reached every one
22 // An astral character and a lone surrogate are one `.` each under the u flag: neither ends a comment.
23 for (const line of ['k = v # \u{1F600} x', 'k = v ; \uD83D x', '# \uDE00\r; y', 'k = "a#b"']) assert.equal(line.slice(0, configCommentStart(line)), line.replace(/[#;].*$/u, ''), JSON.stringify(line));
24});
26test('readConfig: values main read are unchanged, with LF and with CRLF line ends', () => {
27 // Hand-derived from the rule above. With CRLF the CR ends the line after the comment, so main kept the comment in the
28 // value (git itself drops it); this change keeps main's reading and only bounds its cost.
29 const lf = readConfig('[core]\n\tbare = false ; comment\n# [x]\n[Extensions]\n\tObjectFormat = sha256 # why\n');
30 assert.deepEqual([...lf], [['core.bare', 'false'], ['extensions.objectformat', 'sha256']]);
31 const crlf = readConfig('[core]\r\n\tbare = false ; comment\r\n# [x]\r\n[Extensions]\r\n\tObjectFormat = sha256\r\n');
32 assert.deepEqual([...crlf], [['core.bare', 'false ; comment'], ['extensions.objectformat', 'sha256']]);
33});
35test('readConfig: a CRLF line of 64x the comment characters costs under 300x the time (linear is 64x, quadratic 4096x)', () => {
36 // One call on a line of 64n `#` against 64 calls on a line of n: linear work is equal, quadratic work is 64 times
37 // more. Best of 5 each, so load only ever narrows the ratio's noise, never widens it.
38 const N = 500;
39 const small = `[core]\n${'#'.repeat(N)}\r\n`;
40 const big = `[core]\n${'#'.repeat(64 * N)}\r\n`;
41 const best = (fn) => { let b = Infinity; for (let i = 0; i < 5; i++) { const t0 = performance.now(); fn(); b = Math.min(b, performance.now() - t0); } return b; };
42 const smallMs = best(() => { for (let i = 0; i < 64; i++) readConfig(small); }) / 64;
43 const bigMs = best(() => readConfig(big));
44 assert.ok(bigMs < 300 * smallMs, `64x the comment characters cost ${(bigMs / smallMs).toFixed(0)}x the time (${bigMs.toFixed(3)} ms against ${smallMs.toFixed(5)} ms)`);
45});
Diagnostics6 git calls · 191 ms
CallStatusSizeTime0191 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 · 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 · 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=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: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=be7e0453974a5fe832f9065a33bb7e3434c10e9b
Open pack map
fetch2001.5 KiB182 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=182
git.response.bytes=1525
git.response.cache=MISS
git.response.duration_ms=182
git.fetch.wants=74ee15b1ae522eb33a1dbc999efc5cf7ccb73b2c
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=1525
git.pkt.payload.max=1498
git.sideband.band1.bytes=1498
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
a5e147a62c78a140
Request
b2305805…
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