main
ply4 git calls171 ms42 KiB2 cachedprotocol v2
88 lines3.2 KiBRaw
1import { describe, expect, it } from 'vitest';
2import { bucketOf, hashMaterial, inBucket, murmur3_32 } from '../../src/flags/hash.ts';
3import { BUCKETS } from '../../src/flags/ttl.ts';
5const text = new TextEncoder();
7// spaolacci/murmur3 and the Go standard vectors for MurmurHash3_x86_32, seed 0.
8const GOLDEN: readonly { readonly input: string; readonly hash: number }[] = [
9 { input: '', hash: 0x00000000 },
10 { input: 'hello', hash: 0x248bfa47 },
11 { input: 'hello, world', hash: 0x149bbb7f },
12 { input: '19 Jan 2038 at 3:14:07 AM', hash: 0xe31e8a70 },
13 { input: 'The quick brown fox jumps over the lazy dog.', hash: 0xd5c48bfc },
14];
16const BUCKETS_GOLDEN: readonly { readonly unit: string; readonly bucket: number }[] = [
17 { unit: 'anonymous', bucket: 2849 },
18 { unit: 'user-1', bucket: 1777 },
19 { unit: 'user-2', bucket: 8250 },
20];
22describe('murmur3_32', () => {
23 it('matches the published x86_32 vectors', () => {
24 for (const vector of GOLDEN) expect(murmur3_32(text.encode(vector.input), 0)).toBe(vector.hash);
25 });
26});
28describe('bucketOf', () => {
29 it('locks ply.usage.note / v1 buckets', () => {
30 for (const vector of BUCKETS_GOLDEN) expect(bucketOf('ply.usage.note', 'v1', vector.unit)).toBe(vector.bucket);
31 });
33 it('length-prefixes fields so concatenation cannot alias', () => {
34 const left = murmur3_32(hashMaterial('ab', '', 'c'), 0);
35 const right = murmur3_32(hashMaterial('a', 'b', 'c'), 0);
36 expect(left).not.toBe(right);
37 });
38});
40function mulberry32(seed: number): () => number {
41 let state = seed >>> 0;
42 return () => {
43 state = (state + 0x6d2b79f5) >>> 0;
44 let mixed = Math.imul(state ^ (state >>> 15), 1 | state);
45 mixed = (mixed + Math.imul(mixed ^ (mixed >>> 7), 61 | mixed)) ^ mixed;
46 return ((mixed ^ (mixed >>> 14)) >>> 0) / 4294967296;
47 };
50describe('bucketing properties', () => {
51 it('stays inside 0..9999 and is stable', () => {
52 const random = mulberry32(0xC0FFEE);
53 for (let i = 0; i < 200; i++) {
54 const flag = `flag.${Math.floor(random() * 1000)}`;
55 const unit = `u${Math.floor(random() * 1_000_000)}`;
56 const bucket = bucketOf(flag, 'v1', unit);
57 expect(bucket).toBeGreaterThanOrEqual(0);
58 expect(bucket).toBeLessThan(BUCKETS);
59 expect(bucketOf(flag, 'v1', unit)).toBe(bucket);
60 }
61 });
63 it('is monotonic: a unit inside n basis points stays inside every larger allocation', () => {
64 let regressions = 0;
65 for (let bucket = 0; bucket < BUCKETS; bucket += 17) {
66 let seen = false;
67 for (let basisPoints = 0; basisPoints <= BUCKETS; basisPoints++) {
68 const inside = inBucket(bucket, basisPoints);
69 if (seen && !inside) regressions++;
70 if (inside) seen = true;
71 }
72 if (!seen) regressions++;
73 }
74 expect(regressions).toBe(0);
75 expect(inBucket(0, 0)).toBe(false);
76 expect(inBucket(9999, BUCKETS)).toBe(true);
77 expect(inBucket(9999, 9999)).toBe(false);
78 expect(inBucket(0, 1)).toBe(true);
79 });
81 it('puts about half of a fixed sample inside 5000 basis points', () => {
82 let inside = 0;
83 const total = 4000;
84 for (let i = 0; i < total; i++) if (inBucket(bucketOf('ply.usage.note', 'v1', `unit-${i}`), 5_000)) inside++;
85 expect(inside / total).toBeGreaterThan(0.45);
86 expect(inside / total).toBeLessThan(0.55);
87 });
88});
Diagnostics4 git calls · 171 ms
CallStatusSizeTime0171 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
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 1020040 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=165
git.response.bytes=41349
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=526b305930b8ef382f2d7a1f9c0238730a585921
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=41349
git.pkt.payload.max=41254
git.sideband.band1.bytes=41253
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=61
git.pack.bytes=41253
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c
git.pack.full=61
Open pack map
fetch2001.3 KiB165 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1351
git.response.cache=MISS
git.response.duration_ms=165
git.fetch.wants=9b066353b8ca986e4248c5d9533fc56f2154423a
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=1351
git.pkt.payload.max=1330
git.sideband.band1.bytes=1329
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-web.git
Ref
refs/heads/main
Commit
526b305930b8ef382f2d7a1f9c0238730a585921
cf-ray
a5e2e54dfa902947
Request
b0f99dac…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format