Artifactspublic-v0

curl

master
ply4 git calls28 ms290 KiB3 cachedprotocol v2
279 lines8.3 KiBRaw
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "curl_setup.h"
26#include "u32_ptrset.h"
28/* random patterns for API verification */
29#ifdef DEBUGBUILD
30#define CURL_U32_PTRSET_MAGIC 0x75703272
31#endif
33#define CURL_U32_PTRSET_DEBUG 0
35#ifndef CURL_SWAP
36#define CURL_SWAP(a, b) (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b)))
37#endif
39#define CURL_U32_SLOT_CNT(bits) ((bits) ? (1U << (bits)) : 0)
40#define CURL_U32_PTRSET_SLOT_CNT(s) CURL_U32_SLOT_CNT((s)->slotbits)
41#define CURL_U32_PTRSET_SLOT_IDX(s, i) (uint32_t)((i) & (s)->slotmask)
43/* A hashset for tuples (id, ptr) using Robin Hood Hashing.
44 * <https://www.cs.cornell.edu/courses/JavaAndDS/files/hashing_RobinHood.pdf>
45 * The basic idea here to handle collisions by robbing "rich" entries and
46 * giving to the "poor":
47 * - We have an array: (id, ptr) are ideally placed at index "id % size".
48 * - If slot at index is already occupied, we have a collision.
49 * - A simple collision strategy would look at the next index, and the
50 * next until finding an empty slot.
51 * - The drawback is that this may lead to many checks on lookups, as it
52 * will need to also look at subsequent slots until it finds the match.
53 * The amount of lookups is the "probe sequence length" (psl) and this
54 * may vary greatly between entries.
55 * - Robin Hood Hashing balances the 'psl's of all entries more evenly:
56 * - psl == 0 means an entry is in exactly the right slot
57 * - psl == 1 means it is in the slot right after. psl == 2 is the slot
58 * after that, etc.
59 * - when inserting a new entry, track its psl. Finding a slot where
60 * the existing entry has a lower psl makes a swap. Put the new entry
61 * and its psl there, take the previous entry and its psl and find
62 * the next best slot for the previous entry. */
63void Curl_u32_ptrset_init(struct u32_ptrset *set,
64 Curl_u32_ptrset_dtor *dtor)
66 memset(set, 0, sizeof(*set));
67 set->dtor = dtor;
68#ifdef DEBUGBUILD
69 set->init = CURL_U32_PTRSET_MAGIC;
70#endif
73void Curl_u32_ptrset_clear(struct u32_ptrset *set)
75 uint32_t i;
76 DEBUGASSERT(set->init == CURL_U32_PTRSET_MAGIC);
77 if(set->dtor)
78 for(i = 0; i < CURL_U32_PTRSET_SLOT_CNT(set); ++i)
79 if(set->data[i])
80 set->dtor(set->ids[i], set->data[i]);
82 curlx_safefree(set->data);
83 Curl_u32_ptrset_init(set, set->dtor);
86static void u32_ptrset_add(struct u32_ptrset *set, uint32_t id, void *ptr)
88 uint32_t i = CURL_U32_PTRSET_SLOT_IDX(set, id);
89 uint32_t psl = 0;
90 while(set->data[i]) {
91 if(psl > set->psl[i]) { /* SWAP */
92 void *tmpdata;
93#if CURL_U32_PTRSET_DEBUG
94 curl_mfprintf(stderr, "u32_ptrset_add %u=%p to idx=%u\n", id, ptr, i);
95#endif
96 tmpdata = set->data[i];
97 set->data[i] = ptr;
98 ptr = tmpdata;
99 CURL_SWAP(set->psl[i], psl);
100 CURL_SWAP(set->ids[i], id);
101 }
102 i = CURL_U32_PTRSET_SLOT_IDX(set, i + 1);
103 ++psl;
104 }
105 set->ids[i] = id;
106 set->data[i] = ptr;
107 set->psl[i] = psl;
108 ++set->count;
109#if CURL_U32_PTRSET_DEBUG
110 curl_mfprintf(stderr, "u32_ptrset_add %u=%p to idx=%u\n", id, ptr, i);
111#endif
114static bool u32_ptrset_grow(struct u32_ptrset *set)
116 uint32_t i, *prev_ids;
117 uint8_t nslotbits, pslotbits;
118 void **prev_data;
119 size_t nslots;
120 const size_t slot_size = (sizeof(void *) + (2 * sizeof(uint32_t)));
121 void *d;
123 if(set->slotbits >= 31)
124 return FALSE;
125 nslotbits = set->slotbits ? (uint8_t)(set->slotbits + 1) : 5;
126 nslots = CURL_U32_SLOT_CNT(nslotbits);
127 if(nslots > (SIZE_MAX / slot_size)) /* 32-bit arch may trigger here */
128 return FALSE;
129#if CURL_U32_PTRSET_DEBUG
130 curl_mfprintf(stderr, "u32_ptrset_grow from bits=%d to %d, slots=%zu\n",
131 set->slotbits, nslotbits, nslots);
132#endif
133 d = curlx_calloc(1, nslots * slot_size);
134 if(!d)
135 return FALSE;
137 prev_data = set->data;
138 prev_ids = set->ids;
139 pslotbits = set->slotbits;
140#if defined(__GNUC__) && __GNUC__ >= 13
141#pragma GCC diagnostic push
142#pragma GCC diagnostic ignored "-Wanalyzer-allocation-size"
143#endif
144 set->data = d;
145 set->ids = (uint32_t *)(set->data + nslots);
146 set->psl = (uint32_t *)(set->ids + nslots);
147#if defined(__GNUC__) && __GNUC__ >= 13
148#pragma GCC diagnostic pop
149#endif
151 set->slotbits = nslotbits;
152 set->slotmask = (uint32_t)((1U << set->slotbits) - 1);
153 set->count = 0;
154 /* re-add previous entries */
155 for(i = 0; i < CURL_U32_SLOT_CNT(pslotbits); ++i) {
156 if(prev_data[i])
157 u32_ptrset_add(set, prev_ids[i], prev_data[i]);
158 }
159 if(prev_data)
160 curlx_free(prev_data);
161 return TRUE;
164static bool u32_ptrset_get_index(struct u32_ptrset *set,
165 uint32_t id, uint32_t *pindex)
167 uint32_t i = CURL_U32_PTRSET_SLOT_IDX(set, id);
168 uint32_t psl = 0;
169 if(!set->data)
170 return FALSE;
171 while(set->data[i] && (psl <= set->psl[i])) {
172 if(set->ids[i] == id) {
173 *pindex = i;
174#if CURL_U32_PTRSET_DEBUG
175 curl_mfprintf(stderr, "u32_ptrset_index %u=%p at idx=%u\n",
176 id, set->data[i], i);
177#endif
178 return TRUE;
179 }
180 i = CURL_U32_PTRSET_SLOT_IDX(set, i + 1);
181 ++psl;
182 }
183#if CURL_U32_PTRSET_DEBUG
184 curl_mfprintf(stderr, "u32_ptrset_index %u not found\n", id);
185#endif
186 *pindex = 0;
187 return FALSE;
190uint32_t Curl_u32_ptrset_count(struct u32_ptrset *set)
192 return set->count;
195void *Curl_u32_ptrset_get(struct u32_ptrset *set, uint32_t id)
197 uint32_t i;
198 DEBUGASSERT(set->init == CURL_U32_PTRSET_MAGIC);
199 if(u32_ptrset_get_index(set, id, &i))
200 return set->data[i];
201 return NULL;
204CURLcode Curl_u32_ptrset_set(struct u32_ptrset *set,
205 uint32_t id, void *ptr)
207 uint32_t i;
209 DEBUGASSERT(set->init == CURL_U32_PTRSET_MAGIC);
210 if(!ptr) {
211 Curl_u32_ptrset_unset(set, id);
212 return CURLE_OK;
213 }
215 if(u32_ptrset_get_index(set, id, &i)) {
216 /* `id` is in set, replace value */
217 if(set->dtor && (set->data[i] != ptr))
218 set->dtor(set->ids[i], set->data[i]);
219#if CURL_U32_PTRSET_DEBUG
220 curl_mfprintf(stderr, "u32_ptrset_set replace %u=%p at idx=%u\n",
221 id, ptr, i);
222#endif
223 set->data[i] = ptr;
224 return CURLE_OK;
225 }
226 /* `id` not in set yet, grow if full */
227 if((set->count >= CURL_U32_PTRSET_SLOT_CNT(set)) &&
228 !u32_ptrset_grow(set)) {
229 return CURLE_OUT_OF_MEMORY;
230 }
232 u32_ptrset_add(set, id, ptr);
233 return CURLE_OK;
236static void u32_ptrset_unset(struct u32_ptrset *set, uint32_t id)
238 uint32_t i, j;
240 DEBUGASSERT(set->init == CURL_U32_PTRSET_MAGIC);
241 if(u32_ptrset_get_index(set, id, &i)) {
242 /* `id` is in set */
243#if CURL_U32_PTRSET_DEBUG
244 curl_mfprintf(stderr, "u32_ptrset_unset %u at idx=%u\n", id, i);
245#endif
246 if(set->dtor)
247 set->dtor(set->ids[i], set->data[i]);
248 set->data[i] = NULL;
249 set->ids[i] = set->psl[i] = 0;
250 --set->count;
251 j = CURL_U32_PTRSET_SLOT_IDX(set, i + 1);
252 /* shift all entries with positive psl "down" */
253 while(set->data[j] && set->psl[j]) {
254 set->data[i] = set->data[j];
255 set->ids[i] = set->ids[j];
256 set->psl[i] = set->psl[j] - 1;
257 set->data[j] = NULL;
258 set->ids[j] = set->psl[j] = 0;
259 i = j;
260 j = CURL_U32_PTRSET_SLOT_IDX(set, i + 1);
261 }
262 }
265void Curl_u32_ptrset_unset(struct u32_ptrset *set, uint32_t id)
267 u32_ptrset_unset(set, id);
270void Curl_u32_ptrset_visit(struct u32_ptrset *set,
271 Curl_u32_ptrset_visit_cb *cb,
272 void *user_data)
274 uint32_t i;
275 for(i = 0; i < CURL_U32_PTRSET_SLOT_CNT(set); ++i) {
276 if(set->data[i] && !cb(set->ids[i], set->data[i], user_data))
277 break;
278 }
Diagnostics4 git calls · 28 ms
CallStatusSizeTime028 ms
discover200152 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=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-refs200149 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=149
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=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 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=293470
git.response.cache=HIT
git.response.duration_ms=4
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=31c911efe5652725e930f4d2e60c9060e5f6646d
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=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2002.9 KiB · hit21 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=21
git.response.bytes=2976
git.response.cache=HIT
git.response.duration_ms=21
git.fetch.wants=bc0f74c41f598c29e5a050981df1ad57e7deb4b4
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=2976
git.pkt.payload.max=2955
git.sideband.band1.bytes=2954
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/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e1daa81ea6a151
Request
c44fbbcb…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format