@ref0/git 0.27.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/git-http.mjs +29 -12
- package/dist/client/push-upload.mjs +13 -12
- package/dist/client/remote-helper.mjs +1 -1
- package/dist/client/remote.mjs +1 -1
- package/dist/client/run-remote-helper.mjs +7 -14
- package/dist/client/slice-push.d.mts +13 -9
- package/dist/client/slice-push.mjs +16 -5
- package/dist/client/slice-report.mjs +6 -8
- package/dist/client/transport.mjs +27 -5
- package/dist/contracts/git.d.mts +17 -2
- package/dist/contracts/store.d.mts +1 -1
- package/dist/core/forks.mjs +1 -1
- package/dist/core/purge.mjs +1 -1
- package/dist/http/push-uploads.mjs +10 -15
- package/dist/lfs/copy.d.mts +4 -1
- package/dist/lfs/copy.mjs +7 -6
- package/dist/lfs/layer.mjs +1 -1
- package/dist/lfs/objects.mjs +127 -8
- package/dist/lfs/upload-most.mjs +19 -3
- package/dist/merges/merges.d.mts +3 -2
- package/dist/protocol/bytes/buffers.mjs +5 -5
- package/dist/protocol/bytes/crc32.mjs +39 -6
- package/dist/protocol/bytes/deflate.d.mts +11 -31
- package/dist/protocol/bytes/deflate.mjs +133 -72
- package/dist/protocol/bytes/inflate.mjs +2 -2
- package/dist/protocol/bytes/sha1-hasher.mjs +12 -12
- package/dist/protocol/bytes/zlib-ng/README.md +65 -38
- package/dist/protocol/bytes/zlib-ng/compile.d.mts +5 -4
- package/dist/protocol/bytes/zlib-ng/compile.mjs +5 -4
- package/dist/protocol/bytes/zlib-ng/embedded.mjs +1 -1
- package/dist/protocol/bytes/zlib-ng/instance.mjs +14 -8
- package/dist/protocol/bytes/zlib-ng/zlib-ng.wasm +0 -0
- package/dist/protocol/objects/fsck-names.mjs +27 -7
- package/dist/protocol/objects/fsck.mjs +100 -88
- package/dist/protocol/objects/object-rules.d.mts +1 -0
- package/dist/protocol/objects/tree.d.mts +1 -0
- package/dist/protocol/objects/tree.mjs +55 -6
- package/dist/protocol/wire/push-uploads.mjs +12 -1
- package/dist/server/registry.mjs +12 -0
- package/dist/server/server.mjs +7 -1
- package/dist/storage/budget.d.mts +2 -1
- package/dist/storage/budget.mjs +25 -9
- package/dist/storage/calls.d.mts +1 -1
- package/dist/storage/calls.mjs +4 -2
- package/dist/storage/host-bucket.mjs +15 -5
- package/dist/storage/index-bitmaps.d.mts +1 -0
- package/dist/storage/index-bitmaps.mjs +15 -14
- package/dist/storage/index-build.d.mts +2 -1
- package/dist/storage/index-build.mjs +14 -16
- package/dist/storage/index-files.mjs +3 -3
- package/dist/storage/index-graph.mjs +3 -3
- package/dist/storage/index-remap.mjs +6 -7
- package/dist/storage/links.mjs +34 -2
- package/dist/storage/memory-budget.mjs +12 -3
- package/dist/storage/merge-stream.mjs +4 -3
- package/dist/storage/merge-write.mjs +2 -2
- package/dist/storage/pack-receive.mjs +24 -8
- package/dist/storage/packs.d.mts +3 -1
- package/dist/storage/packs.mjs +33 -11
- package/dist/storage/put-holds.d.mts +1 -0
- package/dist/storage/put-holds.mjs +20 -0
- package/dist/storage/ready.mjs +4 -2
- package/dist/storage/receive-bounds.d.mts +1 -1
- package/dist/storage/receive-bounds.mjs +4 -4
- package/dist/storage/receive-links.mjs +31 -15
- package/dist/storage/receive-steps.mjs +21 -1
- package/dist/storage/runs.d.mts +1 -1
- package/dist/storage/runs.mjs +7 -5
- package/dist/store/door.mjs +9 -1
- package/dist/store/job-try.mjs +5 -5
- package/dist/store/repo-record.mjs +1 -1
- package/dist/sync/step.mjs +3 -4
- package/package.json +3 -9
- package/dist/http/node.d.mts +0 -62
- package/dist/http/node.mjs +0 -212
- package/dist/node.d.mts +0 -3
- package/dist/node.mjs +0 -1
- package/dist/server/edge-node.d.mts +0 -19
- package/dist/server/edge-node.mjs +0 -20
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import { allotOrFail, allotScoped, capacityOf } from "./buffers.mjs";
|
|
2
|
+
import { cString, call, instance, openFailure, zlibStatus } from "./zlib-ng/instance.mjs";
|
|
2
3
|
import * as Schema from "effect/Schema";
|
|
3
4
|
import * as Effect from "effect/Effect";
|
|
4
|
-
import
|
|
5
|
+
import * as Result from "effect/Result";
|
|
5
6
|
// src/protocol/bytes/deflate.ts
|
|
6
7
|
/**
|
|
7
8
|
* One zlib member deflated at a time, as a pack holds one per entry, at zlib's defaults: level 6,
|
|
8
9
|
* method 8, window 15, memory level 8, strategy 0, and no flush but the last. Two ways, by size:
|
|
9
10
|
*
|
|
10
|
-
* - An object up to `wholeObjectBytes` is deflated whole by `deflateWhole`, through
|
|
11
|
-
*
|
|
12
|
-
* one
|
|
13
|
-
* waiting in workerd for each one made, written and read, whatever its
|
|
14
|
-
* small objects paid an object (ref0 #3222).
|
|
15
|
-
*
|
|
11
|
+
* - An object up to `wholeObjectBytes` is deflated whole by `deflateWhole`, through zlib-ng
|
|
12
|
+
* 2.3.3's deflate in WebAssembly, `zlib-ng/`, into one buffer of `deflatedMost` its length, in
|
|
13
|
+
* one synchronous call, on one deflater kept and reset between calls. A `CompressionStream`
|
|
14
|
+
* costs about 27 ms of waiting in workerd for each one made, written and read, whatever its
|
|
15
|
+
* size, which a pack of small objects paid an object (ref0 #3222). Deflating push-90mib's
|
|
16
|
+
* 91,258 objects up to 256 KiB took 862 ms of CPU on Node and 933 ms in local workerd, where
|
|
17
|
+
* pako 2.1.0's kept state, which it replaced, took 2,180 and 2,074 ms, for 0.62% more bytes.
|
|
16
18
|
* - A larger one is streamed by `memberDeflater`, through the runtime's
|
|
17
19
|
* `CompressionStream('deflate')`, so what the writer holds never grows with an object's size.
|
|
20
|
+
* It stays there because Workers bill CPU, not waiting: push-90mib's 17 objects past 256 KiB
|
|
21
|
+
* took 911 ms of CPU through it in local workerd and 1,182 ms through zlib-ng, 1.3 times as
|
|
22
|
+
* much, to save a wait of about 27 ms a stream.
|
|
18
23
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
24
|
+
* zlib-ng's matcher and Node's and workerd's Chromium zlib can write other bytes for one object.
|
|
25
|
+
* Both are zlib members any inflater reads; nothing compares compressed bytes, only what they
|
|
26
|
+
* inflate to.
|
|
22
27
|
*
|
|
23
28
|
* The stream's pieces are each awaited with a read always pending, so a stream that accepts input
|
|
24
29
|
* only as its output is read never stalls, and output the compressor hasn't given yet when a write
|
|
@@ -28,12 +33,18 @@ import untyped from "pako/lib/zlib/deflate.js";
|
|
|
28
33
|
* it's handed to returns.
|
|
29
34
|
*/
|
|
30
35
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* 64 KiB `prev` and a 64 KiB `head` table, and a 64 KiB pending buffer, with its state struct.
|
|
34
|
-
* An estimate, held on the meter under `deflater` while a compressor lives.
|
|
36
|
+
* Each of the kept deflater's two buffers in zlib-ng's memory: the one `deflateWhole` copies its
|
|
37
|
+
* input into, a part at a time, and the one it deflates into, copied out as it fills.
|
|
35
38
|
*/
|
|
36
|
-
const
|
|
39
|
+
const deflateWindow = 65536;
|
|
40
|
+
/**
|
|
41
|
+
* The bytes one compressor keeps outside any buffer here, held on the meter under `deflater` while
|
|
42
|
+
* it lives: the kept deflater's stream and state in zlib-ng's memory, 350,304 bytes with zlib-ng
|
|
43
|
+
* 2.3.3 at window 15 and memory level 8, and its two buffers, `deflateWindow` each, which
|
|
44
|
+
* `zlib-ng/instance.test.ts` measures. It covers a `CompressionStream`'s too, zlib's state in the
|
|
45
|
+
* runtime's native memory, which `deflate.c` sizes at about 256 KiB.
|
|
46
|
+
*/
|
|
47
|
+
const deflaterBytes = 482304;
|
|
37
48
|
/**
|
|
38
49
|
* The most bytes zlib deflates `size` bytes into at these settings, above `deflateBound`'s in
|
|
39
50
|
* `deflate.c`: bytes it can't shrink go in stored blocks of a few bytes' header each, and the
|
|
@@ -42,12 +53,11 @@ const deflaterBytes = 262144;
|
|
|
42
53
|
const deflatedMost = (size) => size + Math.ceil(size / 2048) + 64;
|
|
43
54
|
/**
|
|
44
55
|
* The largest object deflated whole: its body and one output buffer of `deflatedMost` its length,
|
|
45
|
-
* beside
|
|
56
|
+
* beside the deflater, about 1 MiB at most. Deflating 256 KiB at level 6 costs a few
|
|
46
57
|
* milliseconds of CPU, well under the stream's wait it replaces, and a call that size keeps a cut
|
|
47
58
|
* by the writer's turn or time bound within milliseconds.
|
|
48
59
|
*/
|
|
49
60
|
const wholeObjectBytes = 262144;
|
|
50
|
-
const zlib = untyped;
|
|
51
61
|
/**
|
|
52
62
|
* A compressor that failed: `compressor` for the runtime's error, and `early end` for a stream
|
|
53
63
|
* that ended before it was closed.
|
|
@@ -141,71 +151,122 @@ const memberDeflater = /* @__PURE__ */ Effect.fnUntraced(function* (meter, emit)
|
|
|
141
151
|
})
|
|
142
152
|
};
|
|
143
153
|
});
|
|
144
|
-
/** zlib's codes and settings, as `lib/zlib/constants.js` gives them. */
|
|
145
|
-
const zOk = 0;
|
|
146
|
-
const zStreamEnd = 1;
|
|
147
|
-
const zFinish = 4;
|
|
148
|
-
const zDeflated = 8;
|
|
149
154
|
/**
|
|
150
|
-
* The
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* the window bytes past the input that it keeps are never matched, as zlib's `deflate.c` says of
|
|
158
|
-
* the `WIN_INIT` zeroing that pako leaves out.
|
|
155
|
+
* The deflater `deflateWhole` keeps between calls, `deflaterBytes` in zlib-ng's memory, placed the
|
|
156
|
+
* first time one runs, and kept for the instance's life, held on no meter between calls: while one
|
|
157
|
+
* runs, its caller holds `deflaterBytes` for it. A call takes it out while it runs, so no two
|
|
158
|
+
* calls ever share it, and puts it back only once it ends whole; a call that finds none, or one on
|
|
159
|
+
* an instance that trapped, places its own. Its blocks are freed only when a call fails, so no
|
|
160
|
+
* inflater takes them otherwise, and an isolate's memory holds one deflater at most. `zd_reset` gives the bytes a fresh deflater
|
|
161
|
+
* would: no match reaches into an earlier call's input.
|
|
159
162
|
*/
|
|
160
163
|
let kept;
|
|
161
|
-
|
|
162
|
-
|
|
164
|
+
const deflateFailed = (failure) => compressorFailed(failure.message);
|
|
165
|
+
/**
|
|
166
|
+
* A deflater and its two buffers, placed together; none if one can't be. `instance.test.ts`
|
|
167
|
+
* measures what it places against `deflaterBytes`.
|
|
168
|
+
*/
|
|
169
|
+
const placeDeflater = (on) => {
|
|
170
|
+
const opened = call(on, (exports) => exports.zd_open());
|
|
171
|
+
if (Result.isFailure(opened)) return Result.fail(opened.failure);
|
|
172
|
+
const stream = opened.success;
|
|
173
|
+
if (stream === 0) return Result.fail(openFailure(on, "deflater"));
|
|
174
|
+
const placed = call(on, (exports) => exports.zn_alloc(2 * deflateWindow));
|
|
175
|
+
if (Result.isFailure(placed)) return Result.fail(placed.failure);
|
|
176
|
+
if (placed.success === 0) {
|
|
177
|
+
const failure = openFailure(on, "deflater");
|
|
178
|
+
call(on, (exports) => exports.zd_close(stream));
|
|
179
|
+
return Result.fail(failure);
|
|
180
|
+
}
|
|
181
|
+
return Result.succeed({
|
|
182
|
+
stream,
|
|
183
|
+
buffers: placed.success
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
/** The kept deflater, reset, or a new one in its place, on the isolate's instance. */
|
|
187
|
+
const takenDeflater = () => {
|
|
163
188
|
const taken = kept;
|
|
164
189
|
kept = void 0;
|
|
165
|
-
if (taken !== void 0 &&
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
190
|
+
if (taken !== void 0 && taken.on.live) {
|
|
191
|
+
const reset = call(taken.on, (exports) => exports.zd_reset(taken.stream));
|
|
192
|
+
if (Result.isSuccess(reset) && reset.success === 0) return Result.succeed(taken);
|
|
193
|
+
ended(taken);
|
|
194
|
+
}
|
|
195
|
+
const made = instance();
|
|
196
|
+
if (Result.isFailure(made)) return Result.fail(made.failure);
|
|
197
|
+
const on = made.success;
|
|
198
|
+
const placed = placeDeflater(on);
|
|
199
|
+
return Result.map(placed, (deflater) => ({
|
|
200
|
+
on,
|
|
201
|
+
...deflater
|
|
202
|
+
}));
|
|
203
|
+
};
|
|
204
|
+
/** Frees a deflater's stream and buffers, unless its instance trapped and was dropped whole. */
|
|
205
|
+
const ended = (deflater) => {
|
|
206
|
+
if (!deflater.on.live) return;
|
|
207
|
+
call(deflater.on, (exports) => {
|
|
208
|
+
exports.zn_release(deflater.buffers);
|
|
209
|
+
exports.zd_close(deflater.stream);
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* `bytes` deflated on `deflater` into `output`, copied in and out `deflateWindow` at a time: how
|
|
214
|
+
* many bytes it wrote, or why it couldn't. Each call into zlib-ng uses input or makes output, or
|
|
215
|
+
* it fails as no progress, and what it makes can't pass `output`'s end.
|
|
216
|
+
*/
|
|
217
|
+
const deflateInto = ({ on, stream, buffers }, bytes, output) => {
|
|
218
|
+
const inputAt = buffers;
|
|
219
|
+
const outputAt = buffers + deflateWindow;
|
|
220
|
+
let loadedFrom = 0;
|
|
221
|
+
let loadedTo = 0;
|
|
222
|
+
let consumed = 0;
|
|
223
|
+
let written = 0;
|
|
224
|
+
for (;;) {
|
|
225
|
+
if (consumed === loadedTo && loadedTo < bytes.byteLength) {
|
|
226
|
+
loadedFrom = consumed;
|
|
227
|
+
loadedTo = Math.min(bytes.byteLength, consumed + deflateWindow);
|
|
228
|
+
on.view.set(bytes.subarray(loadedFrom, loadedTo), inputAt);
|
|
229
|
+
}
|
|
230
|
+
const last = loadedTo === bytes.byteLength ? 1 : 0;
|
|
231
|
+
const stepped = call(on, (exports) => {
|
|
232
|
+
return {
|
|
233
|
+
status: exports.zd_deflate(stream, inputAt + consumed - loadedFrom, loadedTo - consumed, outputAt, deflateWindow, last),
|
|
234
|
+
used: exports.zn_consumed(),
|
|
235
|
+
made: exports.zn_produced()
|
|
236
|
+
};
|
|
237
|
+
});
|
|
238
|
+
if (Result.isFailure(stepped)) return Result.fail(deflateFailed(stepped.failure));
|
|
239
|
+
const { status, used, made } = stepped.success;
|
|
240
|
+
if (status === zlibStatus.error) {
|
|
241
|
+
const message = cString(on, on.exports.zn_message(stream));
|
|
242
|
+
return Result.fail(compressorFailed(message === "" ? "zlib-ng refused" : message));
|
|
243
|
+
}
|
|
244
|
+
if (status !== zlibStatus.end && used === 0 && made === 0) return Result.fail(compressorFailed("zlib-ng made no progress"));
|
|
245
|
+
if (written + made > output.byteLength) return Result.fail(compressorFailed(`the member passed its ${output.byteLength} bytes`));
|
|
246
|
+
output.set(on.view.subarray(outputAt, outputAt + made), written);
|
|
247
|
+
consumed += used;
|
|
248
|
+
written += made;
|
|
249
|
+
if (status === zlibStatus.end) return Result.succeed(written);
|
|
250
|
+
}
|
|
181
251
|
};
|
|
182
252
|
/**
|
|
183
253
|
* One member of `bytes`, deflated whole into one buffer of `deflatedMost` their length and given
|
|
184
|
-
* as a view of what it wrote: a call that can't finish in it
|
|
185
|
-
* holds `deflaterBytes` and `deflatedMost` of their length on
|
|
254
|
+
* as a view of what it wrote: a call that can't finish in it, or a deflater that can't be placed,
|
|
255
|
+
* fails as `compressor`. Its caller holds `deflaterBytes` and `deflatedMost` of their length on
|
|
256
|
+
* its meter while it runs.
|
|
186
257
|
*/
|
|
187
258
|
const deflateWhole = (bytes) => Effect.suspend(() => {
|
|
188
|
-
const
|
|
189
|
-
if (
|
|
259
|
+
const taken = takenDeflater();
|
|
260
|
+
if (Result.isFailure(taken)) return Effect.fail(deflateFailed(taken.failure));
|
|
261
|
+
const deflater = taken.success;
|
|
190
262
|
const output = new Uint8Array(deflatedMost(bytes.byteLength));
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
stream.next_out = 0;
|
|
196
|
-
stream.avail_out = output.byteLength;
|
|
197
|
-
stream.msg = "";
|
|
198
|
-
const status = zlib.deflate(stream, zFinish);
|
|
199
|
-
const written = stream.next_out;
|
|
200
|
-
const message = stream.msg;
|
|
201
|
-
stream.input = null;
|
|
202
|
-
stream.output = null;
|
|
203
|
-
if (status !== zStreamEnd) {
|
|
204
|
-
zlib.deflateEnd(stream);
|
|
205
|
-
return Effect.fail(compressorFailed(message === "" ? `zlib ${status}` : message));
|
|
263
|
+
const written = deflateInto(deflater, bytes, output);
|
|
264
|
+
if (Result.isFailure(written)) {
|
|
265
|
+
ended(deflater);
|
|
266
|
+
return Effect.fail(written.failure);
|
|
206
267
|
}
|
|
207
|
-
if (kept === void 0) kept =
|
|
208
|
-
else
|
|
209
|
-
return Effect.succeed(output.subarray(0, written));
|
|
268
|
+
if (kept === void 0) kept = deflater;
|
|
269
|
+
else ended(deflater);
|
|
270
|
+
return Effect.succeed(output.subarray(0, written.success));
|
|
210
271
|
});
|
|
211
|
-
export { DeflateError, deflateWhole, deflatedMost, deflaterBytes, memberDeflater, wholeObjectBytes };
|
|
272
|
+
export { DeflateError, deflateWhole, deflatedMost, deflaterBytes, memberDeflater, placeDeflater, wholeObjectBytes };
|
|
@@ -61,11 +61,11 @@ const placeInflater = (on) => {
|
|
|
61
61
|
const opened = call(on, (exports) => exports.zn_open());
|
|
62
62
|
if (Result.isFailure(opened)) return Result.fail(opened.failure);
|
|
63
63
|
const stream = opened.success;
|
|
64
|
-
if (stream === 0) return Result.fail(openFailure(on));
|
|
64
|
+
if (stream === 0) return Result.fail(openFailure(on, "inflater"));
|
|
65
65
|
const placed = call(on, (exports) => exports.zn_alloc(2 * inflateWindow));
|
|
66
66
|
if (Result.isFailure(placed)) return Result.fail(placed.failure);
|
|
67
67
|
if (placed.success === 0) {
|
|
68
|
-
const failure = openFailure(on);
|
|
68
|
+
const failure = openFailure(on, "inflater");
|
|
69
69
|
call(on, (exports) => exports.zn_close(stream));
|
|
70
70
|
return Result.fail(failure);
|
|
71
71
|
}
|
|
@@ -9,15 +9,24 @@ const runtime = {
|
|
|
9
9
|
createHash: platform.process?.getBuiltinModule?.("node:crypto").createHash
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
|
-
* A `Sha1Hasher` through the first hash `on` has: `
|
|
13
|
-
* that it holds none of the reader's bytes, then
|
|
14
|
-
* once.
|
|
12
|
+
* A `Sha1Hasher` through the first hash `on` has: `createHash`, each write hashed at once, then
|
|
13
|
+
* `DigestStream`, whose writes are each awaited so that it holds none of the reader's bytes, then
|
|
14
|
+
* `Sha1`. Its digest is read once.
|
|
15
15
|
*
|
|
16
16
|
* A `DigestStream`'s writer is held only while one of its Effects runs, and let go however that
|
|
17
17
|
* ends: a hasher dropped between them locks nothing. One interrupted at a write or its digest is
|
|
18
18
|
* aborted, without waiting, and is done.
|
|
19
19
|
*/
|
|
20
20
|
const sha1HasherOn = (on) => {
|
|
21
|
+
if (on.createHash !== void 0) {
|
|
22
|
+
const hash = on.createHash("sha1");
|
|
23
|
+
return {
|
|
24
|
+
write: (bytes) => Effect.sync(() => {
|
|
25
|
+
hash.update(bytes);
|
|
26
|
+
}),
|
|
27
|
+
digest: Effect.sync(() => Uint8Array.from(hash.digest()))
|
|
28
|
+
};
|
|
29
|
+
}
|
|
21
30
|
if (on.DigestStream !== void 0) {
|
|
22
31
|
const stream = new on.DigestStream("SHA-1");
|
|
23
32
|
stream.digest.catch(() => void 0);
|
|
@@ -34,15 +43,6 @@ const sha1HasherOn = (on) => {
|
|
|
34
43
|
})
|
|
35
44
|
};
|
|
36
45
|
}
|
|
37
|
-
if (on.createHash !== void 0) {
|
|
38
|
-
const hash = on.createHash("sha1");
|
|
39
|
-
return {
|
|
40
|
-
write: (bytes) => Effect.sync(() => {
|
|
41
|
-
hash.update(bytes);
|
|
42
|
-
}),
|
|
43
|
-
digest: Effect.sync(() => Uint8Array.from(hash.digest()))
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
46
|
const sha = new Sha1();
|
|
47
47
|
return {
|
|
48
48
|
write: (bytes) => Effect.sync(() => sha.update(bytes)),
|
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
# zlib-ng.wasm
|
|
2
2
|
|
|
3
|
-
zlib-ng's inflate compiled to WebAssembly
|
|
4
|
-
member a pack holds: one member at a time, stopping at its end with its
|
|
5
|
-
reporting exactly the input it used, as zlib does.
|
|
6
|
-
|
|
3
|
+
zlib-ng's inflate, deflate and CRC-32 compiled to WebAssembly. [`inflate.ts`](../inflate.ts) runs
|
|
4
|
+
its inflate for every zlib member a pack holds: one member at a time, stopping at its end with its
|
|
5
|
+
Adler-32 checked and reporting exactly the input it used, as zlib does. [`deflate.ts`](../deflate.ts)
|
|
6
|
+
runs its deflate for every object up to `wholeObjectBytes` a pack is written with, and
|
|
7
|
+
[`crc32.ts`](../crc32.ts) its CRC-32 for each entry a pack index keeps. They replaced pako's, which
|
|
8
|
+
took 2.5 times as long to inflate the same pack, 2.2 to 2.5 times as long to deflate its objects,
|
|
9
|
+
and 3.2 to 4.1 times as long for their CRC-32s.
|
|
7
10
|
|
|
8
11
|
zlib-ng is under the zlib licence, which Apache-2.0 allows, so it lives inside `@ref0/git` and a
|
|
9
12
|
host passes nothing.
|
|
10
13
|
|
|
11
14
|
## What's here
|
|
12
15
|
|
|
13
|
-
| Path | What it is
|
|
14
|
-
| ------------------- |
|
|
15
|
-
| `upstream/` | zlib-ng 2.3.3's files the build compiles or includes, unchanged, its three header templates, and its `LICENSE.md`
|
|
16
|
-
| `adapter/adapter.c` | The exports: a heap that grows and reuses what it frees, the C library routines zlib-ng calls, and a stream for each inflater |
|
|
17
|
-
| `adapter/shim/` | The four C library headers zlib-ng includes, for a build with no C library
|
|
18
|
-
| `build.sh` | Builds the artifact with a pinned Zig and checks it matches `zlib-ng.wasm` byte for byte, and `embedded.ts` matches it too
|
|
19
|
-
| `zlib-ng.wasm` | The artifact, checked in: JS builds use it and never run Zig
|
|
20
|
-
| `zlib-ng.wasm.d.ts` | Its type as `#zlib-ng/zlib-ng.wasm`, which a Worker's bundler hands over compiled: a `WebAssembly.Module`
|
|
21
|
-
| `embedded.ts` | The artifact's bytes as base64, which `build.sh --update` writes and its check compares with `zlib-ng.wasm`
|
|
22
|
-
| `bundled.ts` | `#zlib-ng` in a Worker, its `workerd` condition: the module the bundler compiled from `zlib-ng.wasm`
|
|
23
|
-
| `compile.ts` | `#zlib-ng` everywhere else, Node, Vercel and a browser: `embedded.ts` compiled the first time
|
|
24
|
-
| `instance.ts` | One instance an isolate, made
|
|
16
|
+
| Path | What it is |
|
|
17
|
+
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
18
|
+
| `upstream/` | zlib-ng 2.3.3's files the build compiles or includes, unchanged, its three header templates, and its `LICENSE.md` |
|
|
19
|
+
| `adapter/adapter.c` | The exports: a heap that grows and reuses what it frees, the C library routines zlib-ng calls, and a stream for each inflater and deflater |
|
|
20
|
+
| `adapter/shim/` | The four C library headers zlib-ng includes, for a build with no C library |
|
|
21
|
+
| `build.sh` | Builds the artifact with a pinned Zig and checks it matches `zlib-ng.wasm` byte for byte, and `embedded.ts` matches it too |
|
|
22
|
+
| `zlib-ng.wasm` | The artifact, checked in: JS builds use it and never run Zig |
|
|
23
|
+
| `zlib-ng.wasm.d.ts` | Its type as `#zlib-ng/zlib-ng.wasm`, which a Worker's bundler hands over compiled: a `WebAssembly.Module` |
|
|
24
|
+
| `embedded.ts` | The artifact's bytes as base64, which `build.sh --update` writes and its check compares with `zlib-ng.wasm` |
|
|
25
|
+
| `bundled.ts` | `#zlib-ng` in a Worker, its `workerd` condition: the module the bundler compiled from `zlib-ng.wasm` |
|
|
26
|
+
| `compile.ts` | `#zlib-ng` everywhere else, Node, Vercel and a browser: `embedded.ts` compiled the first time it's called, and kept |
|
|
27
|
+
| `instance.ts` | One instance an isolate, made the first time it's called, and calls into it, a trap answered as a failure that drops it |
|
|
25
28
|
|
|
26
29
|
`@ref0/git`'s `package.json` maps `#zlib-ng` and `#zlib-ng/zlib-ng.wasm` in `imports`, and its
|
|
27
30
|
`publishConfig.imports` maps them in the build, where `vite.config.ts` copies `zlib-ng.wasm`,
|
|
@@ -45,10 +48,11 @@ this README and zlib-ng's licence.
|
|
|
45
48
|
## How it's built
|
|
46
49
|
|
|
47
50
|
`build.sh` runs the Zig its `zig_version` pins, checking the tarball's SHA-256 it copies from
|
|
48
|
-
ziglang.org's `index.json`, with its caches in a scratch folder. It compiles zlib-ng's generic C
|
|
49
|
-
with its functions picked at build time
|
|
50
|
-
CRC, for `wasm32-freestanding` with no C
|
|
51
|
-
no faster on a pack. The flags are in the
|
|
51
|
+
ziglang.org's `index.json`, with its caches in a scratch folder. It compiles zlib-ng's generic C,
|
|
52
|
+
its inflate, its deflate and its CRC-32, with its functions picked at build time
|
|
53
|
+
(`DISABLE_RUNTIME_CPU_DETECTION`), no gzip and no Chorba CRC, for `wasm32-freestanding` with no C
|
|
54
|
+
library and no entry, without `simd128`, which measured no faster on a pack. The flags are in the
|
|
55
|
+
script.
|
|
52
56
|
|
|
53
57
|
```sh
|
|
54
58
|
packages/git/src/protocol/bytes/zlib-ng/build.sh # download Zig, build, compare with zlib-ng.wasm and embedded.ts
|
|
@@ -56,29 +60,29 @@ packages/git/src/protocol/bytes/zlib-ng/build.sh --zig <zig> # the same with a
|
|
|
56
60
|
packages/git/src/protocol/bytes/zlib-ng/build.sh --update # replace zlib-ng.wasm, and write embedded.ts from it
|
|
57
61
|
```
|
|
58
62
|
|
|
59
|
-
| |
|
|
60
|
-
| ------- |
|
|
61
|
-
| Size |
|
|
62
|
-
| SHA-256 | `
|
|
63
|
-
| Ceiling |
|
|
64
|
-
| Memory | imported, at least 2 pages, a 32 KiB stack among them; no most of its own
|
|
65
|
-
| Imports | `env.memory`
|
|
66
|
-
| Exports | `zn_alloc`, `zn_release`, `zn_open`, `zn_reset`, `zn_close`, `zn_inflate`, `zn_consumed`, `zn_produced`, `zn_message`, `zn_failure`, `zn_heap_top` |
|
|
63
|
+
| | |
|
|
64
|
+
| ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
65
|
+
| Size | 62,741 bytes; 26,951 with `gzip -9 -n`, gzip 1.14 |
|
|
66
|
+
| SHA-256 | `f2fa2d1f5e300a3bb73f99d45856a96712b8a84c94faf100fb187c715418c5e2` |
|
|
67
|
+
| Ceiling | 65,536 bytes, which `build.sh` fails past |
|
|
68
|
+
| Memory | imported, at least 2 pages, a 32 KiB stack and the CRC's 32 KiB input among them; no most of its own |
|
|
69
|
+
| Imports | `env.memory` |
|
|
70
|
+
| Exports | `zn_alloc`, `zn_release`, `zn_open`, `zn_reset`, `zn_close`, `zn_inflate`, `zd_open`, `zd_reset`, `zd_close`, `zd_deflate`, `zn_crc32_input`, `zn_crc32`, `zn_consumed`, `zn_produced`, `zn_message`, `zn_failure`, `zn_heap_top` |
|
|
67
71
|
|
|
68
72
|
No CI job runs `build.sh` on its own. Change an adapter file, a flag or the Zig version only with a
|
|
69
|
-
rebuild, the new hash and size here and in `build.sh`, and a run of `embedded.test.ts
|
|
70
|
-
`instance.test.ts` here and `inflate.test.ts`, `inflate.fuzz.test.ts
|
|
71
|
-
beside it.
|
|
73
|
+
rebuild, the new hash and size here and in `build.sh`, and a run of `embedded.test.ts`,
|
|
74
|
+
`instance.test.ts` and `memory-cap.test.ts` here and `inflate.test.ts`, `inflate.fuzz.test.ts`,
|
|
75
|
+
`deflate.test.ts`, `deflate.fuzz.test.ts`, `crc32.test.ts` and `packs/` beside it.
|
|
72
76
|
|
|
73
77
|
## The ABI
|
|
74
78
|
|
|
75
79
|
Calls on one instance run one at a time, each to its end, as JavaScript makes them. The module
|
|
76
|
-
imports its memory, and `instance.ts` makes it with a most, `
|
|
80
|
+
imports its memory, and `instance.ts` makes it with a most, `zlibNgMemoryBytes` in
|
|
77
81
|
[`buffers.ts`](../buffers.ts), with the isolate's other bounds: what a 128 MB isolate's operations
|
|
78
82
|
are allotted, 103,284,736 bytes. Past it, the heap's grow answers no memory, so `zn_open` or the
|
|
79
|
-
inflater's `zn_alloc` answers 0 and the inflater fails as `InflateError`, never a trap
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
inflater's `zn_alloc` answers 0 and the inflater fails as `InflateError`, never a trap; `zd_open`
|
|
84
|
+
or the deflater's `zn_alloc` the same, as `DeflateError`. zlib-ng allocates only in `inflateInit`
|
|
85
|
+
and `deflateInit`, and each places its buffers as it opens, so an open stream never needs more.
|
|
82
86
|
|
|
83
87
|
1. `zn_open()` places a stream and its state, a 32 KiB window among it, for a zlib wrapper and
|
|
84
88
|
any window to 32 KiB, and answers its address, or 0, with `zn_failure()` 1 when memory can't grow
|
|
@@ -93,13 +97,36 @@ inflater never needs more.
|
|
|
93
97
|
member's history. 0, or -1.
|
|
94
98
|
4. `zn_close(stream)` runs `zng_inflateEnd` and frees the stream.
|
|
95
99
|
|
|
100
|
+
5. `zd_open()` places a deflate stream at zlib's defaults, level 6, a zlib wrapper, a 32 KiB
|
|
101
|
+
window, memory level 8 and the default strategy, and answers its address, or 0, with
|
|
102
|
+
`zn_failure()` as `zn_open` sets it.
|
|
103
|
+
6. `zd_deflate(stream, in, length, out, capacity, last)` runs `zng_deflate`, with `Z_FINISH` when
|
|
104
|
+
`last` is 1 and `Z_NO_FLUSH` otherwise: 2 wrote the member's end, its Adler-32 last, 1 filled its
|
|
105
|
+
output, 0 used all its input and wants more, -1 zlib-ng refused and -2 made no progress, its
|
|
106
|
+
bytes counted by `zn_consumed()` and `zn_produced()` as `zn_inflate`'s are.
|
|
107
|
+
7. `zd_reset(stream)` runs `zng_deflateReset`, for a new member with none of the last one's input
|
|
108
|
+
matched, 0 or -1, and `zd_close(stream)` runs `zng_deflateEnd` and frees the stream.
|
|
109
|
+
|
|
110
|
+
8. `zn_crc32_input()` answers the address of a 32 KiB buffer in the module's own data, and
|
|
111
|
+
`zn_crc32(crc, length)` runs `zng_crc32` over its first `length` bytes, 32 KiB at most, from
|
|
112
|
+
`crc`. The buffer is placed with the module, so a CRC places nothing and never fails for memory.
|
|
113
|
+
|
|
96
114
|
`zn_alloc(size)` places a buffer for the host, or answers 0, and `zn_release(at)` frees it.
|
|
97
|
-
`zn_heap_top()` gives the
|
|
98
|
-
|
|
99
|
-
|
|
115
|
+
`zn_heap_top()` gives the heap's top, just past its last block in use. The heap takes the
|
|
116
|
+
smallest free block that fits, so each stream's blocks are reused whole by the next of its kind,
|
|
117
|
+
and splits a larger one, leaving its rest free. A freed block is joined to the free blocks either
|
|
118
|
+
side of it, and given back to the top when it ends there, so the memory inflaters freed holds a
|
|
119
|
+
deflater. Linear memory never shrinks, and its high-water mark is the most an isolate held at once.
|
|
100
120
|
|
|
101
121
|
Each stream holds 42,144 bytes. An inflater places one, and two buffers of `inflateWindow`, 64 KiB:
|
|
102
122
|
one it copies its input into, a part of a chunk once however many members that part holds, and one
|
|
103
123
|
it inflates into. `inflaterBytes` covers the three, and `instance.test.ts` measures them. The pack
|
|
104
124
|
reader copies its output out to its own buffer at once: a sink may keep a piece until its Effect
|
|
105
125
|
ends, and another read's inflater may grow the memory before then, detaching any view of it.
|
|
126
|
+
|
|
127
|
+
The deflater holds 350,304 bytes, its stream and state, and two buffers of 64 KiB, which
|
|
128
|
+
`deflaterBytes` covers and `instance.test.ts` measures. [`deflate.ts`](../deflate.ts) keeps one for
|
|
129
|
+
the instance's life, placed the first time an object is deflated whole: its calls run one at a
|
|
130
|
+
time, each to its end, so one is all an isolate needs. Its blocks are freed only when a call fails,
|
|
131
|
+
so no inflater takes one otherwise. While inflaters fill the memory to its most, a deflater can't
|
|
132
|
+
be placed and that write fails as `DeflateError`; once they end, the next one places it.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `zlib-ng.wasm`, as `#zlib-ng` answers outside a Worker: in Node, on Vercel and in a browser.
|
|
3
|
-
* It compiles the bytes `embedded.ts` holds as base64 the first time an inflater opens,
|
|
4
|
-
* the module, so a bundler or a file tracer has no
|
|
5
|
-
* compiles nothing. It compiles synchronously, as
|
|
6
|
-
* that on its main thread up to 8 MB, and the module
|
|
3
|
+
* It compiles the bytes `embedded.ts` holds as base64 the first time an inflater opens, an object
|
|
4
|
+
* is deflated whole or a CRC-32 taken, and keeps the module, so a bundler or a file tracer has no
|
|
5
|
+
* file to ship and a host that does none of them compiles nothing. It compiles synchronously, as
|
|
6
|
+
* each of them runs synchronously: Chrome allows that on its main thread up to 8 MB, and the module
|
|
7
|
+
* is 62 KB.
|
|
7
8
|
*/
|
|
8
9
|
export declare const zlibNgModule: () => WebAssembly.Module;
|
|
@@ -3,10 +3,11 @@ import { zlibNgBase64 } from "./embedded.mjs";
|
|
|
3
3
|
let compiled;
|
|
4
4
|
/**
|
|
5
5
|
* `zlib-ng.wasm`, as `#zlib-ng` answers outside a Worker: in Node, on Vercel and in a browser.
|
|
6
|
-
* It compiles the bytes `embedded.ts` holds as base64 the first time an inflater opens,
|
|
7
|
-
* the module, so a bundler or a file tracer has no
|
|
8
|
-
* compiles nothing. It compiles synchronously, as
|
|
9
|
-
* that on its main thread up to 8 MB, and the module
|
|
6
|
+
* It compiles the bytes `embedded.ts` holds as base64 the first time an inflater opens, an object
|
|
7
|
+
* is deflated whole or a CRC-32 taken, and keeps the module, so a bundler or a file tracer has no
|
|
8
|
+
* file to ship and a host that does none of them compiles nothing. It compiles synchronously, as
|
|
9
|
+
* each of them runs synchronously: Chrome allows that on its main thread up to 8 MB, and the module
|
|
10
|
+
* is 62 KB.
|
|
10
11
|
*/
|
|
11
12
|
const zlibNgModule = () => {
|
|
12
13
|
if (compiled !== void 0) return compiled;
|