knitting 0.1.56 → 0.1.61
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/BROWSER.md +134 -0
- package/README.md +347 -46
- package/knitting.browser.d.ts +6 -0
- package/knitting.browser.js +1 -0
- package/knitting.d.ts +3 -2
- package/knitting.js +3 -3
- package/map.md +21 -9
- package/package.json +17 -2
- package/prebuilds/darwin-arm64-node-127/knitting_buffer_pointer.node +0 -0
- package/prebuilds/darwin-arm64-node-127/knitting_shared_memory.node +0 -0
- package/prebuilds/darwin-arm64-node-127/knitting_shm.node +0 -0
- package/prebuilds/darwin-arm64-node-137/knitting_buffer_pointer.node +0 -0
- package/prebuilds/darwin-arm64-node-137/knitting_shared_memory.node +0 -0
- package/prebuilds/darwin-arm64-node-137/knitting_shm.node +0 -0
- package/prebuilds/win32-x64/knitting_windows_shared_memory.dll +0 -0
- package/prebuilds/win32-x64-node-127/knitting_buffer_pointer.node +0 -0
- package/prebuilds/win32-x64-node-127/knitting_shared_memory.node +0 -0
- package/prebuilds/win32-x64-node-127/knitting_shm.node +0 -0
- package/prebuilds/win32-x64-node-137/knitting_buffer_pointer.node +0 -0
- package/prebuilds/win32-x64-node-137/knitting_shared_memory.node +0 -0
- package/prebuilds/win32-x64-node-137/knitting_shm.node +0 -0
- package/scripts/build-compiled-worker.ts +276 -0
- package/scripts/compiled-worker/porffor.d.ts +5 -0
- package/scripts/compiled-worker/runtime.ts +529 -0
- package/scripts/compiled-worker/task-shim.ts +32 -0
- package/src/api.d.ts +24 -1
- package/src/api.js +311 -27
- package/src/common/module-url.d.ts +1 -0
- package/src/common/module-url.js +30 -2
- package/src/common/node-compat.d.ts +2 -0
- package/src/common/path-canonical.js +20 -6
- package/src/common/runtime.d.ts +3 -1
- package/src/common/runtime.js +25 -4
- package/src/common/task-source.d.ts +2 -0
- package/src/common/task-source.js +17 -1
- package/src/common/worker-runtime.js +16 -7
- package/src/connections/buffer-reference-native.js +25 -1
- package/src/connections/buffer-reference.d.ts +23 -2
- package/src/connections/buffer-reference.js +143 -29
- package/src/connections/bun.d.ts +1 -1
- package/src/connections/bun.js +25 -14
- package/src/connections/deno.d.ts +3 -1
- package/src/connections/deno.js +35 -14
- package/src/connections/external-array-buffer.d.ts +2 -0
- package/src/connections/external-array-buffer.js +33 -0
- package/src/connections/node-addons.d.ts +11 -0
- package/src/connections/node-addons.js +49 -1
- package/src/connections/node-ffi-api.d.ts +19 -0
- package/src/connections/node-ffi-api.js +28 -0
- package/src/connections/node-ffi.d.ts +27 -0
- package/src/connections/node-ffi.js +262 -0
- package/src/connections/node.d.ts +1 -1
- package/src/connections/node.js +20 -20
- package/src/connections/package-assets.js +25 -15
- package/src/connections/posix.d.ts +42 -0
- package/src/connections/posix.js +101 -0
- package/src/connections/process-shared-buffer.d.ts +1 -0
- package/src/connections/process-shared-buffer.js +11 -45
- package/src/connections/types.d.ts +4 -0
- package/src/connections/windows.d.ts +19 -10
- package/src/connections/windows.js +87 -66
- package/src/error.d.ts +7 -6
- package/src/error.js +8 -7
- package/src/memory/lock.d.ts +112 -77
- package/src/memory/lock.js +314 -87
- package/src/memory/payloadCodec.d.ts +11 -2
- package/src/memory/payloadCodec.js +129 -37
- package/src/memory/regionRegistry.d.ts +1 -3
- package/src/memory/regionRegistry.js +16 -14
- package/src/permission/compatibility.d.ts +28 -0
- package/src/permission/compatibility.js +239 -0
- package/src/permission/index.d.ts +2 -0
- package/src/permission/index.js +1 -0
- package/src/permission/protocol.d.ts +1 -0
- package/src/permission/protocol.js +59 -15
- package/src/runtime/compiled-artifact.d.ts +21 -0
- package/src/runtime/compiled-artifact.js +260 -0
- package/src/runtime/compiled-builder.d.ts +8 -0
- package/src/runtime/compiled-builder.js +42 -0
- package/src/runtime/compiled-worker.d.ts +27 -0
- package/src/runtime/compiled-worker.js +562 -0
- package/src/runtime/dispatcher.js +9 -0
- package/src/runtime/inline-executor.js +27 -15
- package/src/runtime/pool.d.ts +121 -5
- package/src/runtime/pool.js +263 -49
- package/src/runtime/process-worker.d.ts +3 -13
- package/src/runtime/process-worker.js +97 -101
- package/src/runtime/tx-queue.d.ts +18 -2
- package/src/runtime/tx-queue.js +56 -16
- package/src/runtime/worker-common.d.ts +13 -0
- package/src/runtime/worker-common.js +102 -0
- package/src/types.d.ts +89 -9
- package/src/worker/composable-runners.js +3 -2
- package/src/worker/loop.d.ts +1 -0
- package/src/worker/loop.js +52 -17
- package/src/worker/rx-queue.d.ts +11 -1
- package/src/worker/rx-queue.js +4 -1
- package/src/worker/task-loader.d.ts +5 -4
- package/src/worker/task-loader.js +13 -7
- package/src/worker/timers.d.ts +8 -1
- package/src/worker/timers.js +28 -23
package/src/memory/lock.d.ts
CHANGED
|
@@ -1,70 +1,77 @@
|
|
|
1
1
|
import RingQueue from "../ipc/tools/ring-queue.js";
|
|
2
|
+
type EncodePayloadFactory = typeof import("./payloadCodec.js").encodePayload;
|
|
3
|
+
type DecodePayloadFactory = typeof import("./payloadCodec.js").decodePayload;
|
|
4
|
+
export declare const registerLockPayloadCodec: (encode: EncodePayloadFactory, decode: DecodePayloadFactory) => void;
|
|
2
5
|
import { type SharedBufferSource } from "../common/shared-buffer-region.js";
|
|
3
6
|
import { type LockBufferTextCompat } from "../common/shared-buffer-text.js";
|
|
4
7
|
import { type PayloadBufferOptions } from "./payload-config.js";
|
|
5
8
|
/**
|
|
6
9
|
* TODO: Compose all the instance where the array is passed as argument
|
|
7
10
|
*/
|
|
8
|
-
export declare
|
|
9
|
-
UNREACHABLE
|
|
10
|
-
BigInt
|
|
11
|
-
True
|
|
12
|
-
False
|
|
13
|
-
Undefined
|
|
14
|
-
NaN
|
|
15
|
-
Float64
|
|
16
|
-
Null
|
|
17
|
-
}
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
11
|
+
export declare const PayloadSignal: {
|
|
12
|
+
readonly UNREACHABLE: 0;
|
|
13
|
+
readonly BigInt: 2;
|
|
14
|
+
readonly True: 3;
|
|
15
|
+
readonly False: 4;
|
|
16
|
+
readonly Undefined: 5;
|
|
17
|
+
readonly NaN: 6;
|
|
18
|
+
readonly Float64: 9;
|
|
19
|
+
readonly Null: 10;
|
|
20
|
+
};
|
|
21
|
+
export type PayloadSignal = typeof PayloadSignal[keyof typeof PayloadSignal];
|
|
22
|
+
export declare const PayloadBuffer: {
|
|
23
|
+
readonly BORDER_SIGNAL_BUFFER: 11;
|
|
24
|
+
readonly String: 11;
|
|
25
|
+
readonly Json: 12;
|
|
26
|
+
readonly StaticString: 15;
|
|
27
|
+
readonly StaticJson: 16;
|
|
28
|
+
readonly Binary: 17;
|
|
29
|
+
readonly StaticBinary: 18;
|
|
30
|
+
readonly Int32Array: 19;
|
|
31
|
+
readonly Float64Array: 20;
|
|
32
|
+
readonly BigInt64Array: 21;
|
|
33
|
+
readonly BigUint64Array: 22;
|
|
34
|
+
readonly DataView: 23;
|
|
35
|
+
readonly Error: 24;
|
|
36
|
+
readonly Date: 25;
|
|
37
|
+
readonly Symbol: 26;
|
|
38
|
+
readonly StaticSymbol: 27;
|
|
39
|
+
readonly BigInt: 28;
|
|
40
|
+
readonly StaticBigInt: 29;
|
|
41
|
+
readonly StaticInt32Array: 31;
|
|
42
|
+
readonly StaticFloat64Array: 32;
|
|
43
|
+
readonly StaticBigInt64Array: 33;
|
|
44
|
+
readonly StaticBigUint64Array: 34;
|
|
45
|
+
readonly StaticDataView: 35;
|
|
46
|
+
readonly ArrayBuffer: 36;
|
|
47
|
+
readonly StaticArrayBuffer: 37;
|
|
48
|
+
readonly Buffer: 38;
|
|
49
|
+
readonly StaticBuffer: 39;
|
|
50
|
+
readonly EnvelopeStaticHeader: 40;
|
|
51
|
+
readonly EnvelopeDynamicHeader: 41;
|
|
52
|
+
readonly EnvelopeStaticHeaderString: 42;
|
|
53
|
+
readonly EnvelopeDynamicHeaderString: 43;
|
|
54
|
+
readonly ExternalPayload: 44;
|
|
55
|
+
readonly StaticExternalPayload: 45;
|
|
56
|
+
readonly ProcessSharedBuffer: 46;
|
|
57
|
+
readonly BufferReference: 47;
|
|
58
|
+
readonly SharedArrayBuffer: 48;
|
|
59
|
+
readonly EnvelopeStaticHeaderExternal: 49;
|
|
60
|
+
readonly EnvelopeDynamicHeaderExternal: 50;
|
|
61
|
+
readonly EnvelopeStaticHeaderStringExternal: 51;
|
|
62
|
+
readonly EnvelopeDynamicHeaderStringExternal: 52;
|
|
63
|
+
readonly NumericArray: 53;
|
|
64
|
+
readonly StaticNumericArray: 54;
|
|
65
|
+
};
|
|
66
|
+
export type PayloadBuffer = typeof PayloadBuffer[keyof typeof PayloadBuffer];
|
|
67
|
+
export declare const payloadBufferName: (value: number) => string;
|
|
68
|
+
export declare const LockBound: {
|
|
69
|
+
readonly paddingLock: 0;
|
|
70
|
+
readonly padding: 0;
|
|
71
|
+
readonly slots: 32;
|
|
72
|
+
readonly header: 0;
|
|
73
|
+
};
|
|
74
|
+
export type LockBound = typeof LockBound[keyof typeof LockBound];
|
|
68
75
|
export declare const LOCK_CACHE_LINE_BYTES = 64;
|
|
69
76
|
export declare const LOCK_SECTOR_BYTES = 256;
|
|
70
77
|
export type Task = [
|
|
@@ -92,33 +99,34 @@ export declare const resetTaskLocalFlags: (task: Task) => void;
|
|
|
92
99
|
export declare const addTaskFinalizer: (task: Task, finalizer: () => void) => void;
|
|
93
100
|
export declare const attachPayloadTransportFinalizer: (task: Task, value: unknown) => void;
|
|
94
101
|
export declare const runTaskFinalizers: (task: Task) => void;
|
|
95
|
-
export declare
|
|
102
|
+
export declare const TaskIndex: {
|
|
96
103
|
/**
|
|
97
104
|
* Worker -> host response flags word.
|
|
98
105
|
*/
|
|
99
|
-
FlagsToHost
|
|
106
|
+
readonly FlagsToHost: 0;
|
|
100
107
|
/**
|
|
101
108
|
* Host -> worker request function id (low 16 bits).
|
|
102
109
|
* High 16 bits are reserved for caller metadata on request path.
|
|
103
110
|
* NOTE: shares the same storage word as `FlagsToHost`.
|
|
104
111
|
*/
|
|
105
|
-
FunctionID
|
|
106
|
-
ID
|
|
107
|
-
Type
|
|
108
|
-
Start
|
|
109
|
-
End
|
|
110
|
-
PayloadLen
|
|
112
|
+
readonly FunctionID: 0;
|
|
113
|
+
readonly ID: 1;
|
|
114
|
+
readonly Type: 2;
|
|
115
|
+
readonly Start: 3;
|
|
116
|
+
readonly End: 4;
|
|
117
|
+
readonly PayloadLen: 5;
|
|
111
118
|
/**
|
|
112
119
|
* Low 5 bits: region slot index (0..31).
|
|
113
120
|
* High 27 bits: reserved for caller metadata (e.g. enqueue timing).
|
|
114
121
|
*/
|
|
115
|
-
slotBuffer
|
|
116
|
-
Size
|
|
122
|
+
readonly slotBuffer: 6;
|
|
123
|
+
readonly Size: 8;
|
|
117
124
|
/**
|
|
118
125
|
* Total slot length in Uint32 words, including the task header.
|
|
119
126
|
*/
|
|
120
|
-
TotalBuff
|
|
121
|
-
}
|
|
127
|
+
readonly TotalBuff: 144;
|
|
128
|
+
};
|
|
129
|
+
export type TaskIndex = typeof TaskIndex[keyof typeof TaskIndex];
|
|
122
130
|
export declare const TASK_SLOT_INDEX_BITS = 5;
|
|
123
131
|
export declare const TASK_SLOT_INDEX_MASK: number;
|
|
124
132
|
export declare const TASK_SLOT_META_BITS: number;
|
|
@@ -135,11 +143,12 @@ export declare const getTaskSlotIndex: (task: ArrayLike<number>) => number;
|
|
|
135
143
|
export declare const setTaskSlotIndex: (task: Task, slotIndex: number) => void;
|
|
136
144
|
export declare const getTaskSlotMeta: (task: ArrayLike<number>) => number;
|
|
137
145
|
export declare const setTaskSlotMeta: (task: Task, value: number) => void;
|
|
138
|
-
export declare
|
|
139
|
-
Reject
|
|
140
|
-
}
|
|
146
|
+
export declare const TaskFlag: {
|
|
147
|
+
readonly Reject: 1;
|
|
148
|
+
};
|
|
149
|
+
export type TaskFlag = typeof TaskFlag[keyof typeof TaskFlag];
|
|
141
150
|
export declare const LOCK_WORD_BYTES: number;
|
|
142
|
-
export declare const LOCK_HOST_BITS_OFFSET_BYTES
|
|
151
|
+
export declare const LOCK_HOST_BITS_OFFSET_BYTES: 0;
|
|
143
152
|
export declare const LOCK_WORKER_BITS_OFFSET_BYTES = 64;
|
|
144
153
|
export declare const LOCK_SECTOR_BYTE_LENGTH = 256;
|
|
145
154
|
export declare const PAYLOAD_LOCK_HOST_BITS_OFFSET_BYTES: number;
|
|
@@ -150,6 +159,20 @@ export declare const HEADER_SLOT_STRIDE_BYTES: number;
|
|
|
150
159
|
export declare const HEADER_TASK_LINE_U32: number;
|
|
151
160
|
export declare const HEADER_STATIC_PAYLOAD_U32: number;
|
|
152
161
|
export declare const HEADER_TASK_OFFSET_IN_SLOT_U32: number;
|
|
162
|
+
export declare const STEAL_ACK_SLOT_OFFSET_U32: number;
|
|
163
|
+
export declare const STEAL_WANT_SLOT_OFFSET_U32: number;
|
|
164
|
+
/**
|
|
165
|
+
* The payload allocator needs its own participant-owned ACK per consumer, since
|
|
166
|
+
* several workers can free payload slots from one shared allocator. No intent
|
|
167
|
+
* word: freeing needs no arbitration, a consumer only frees what it drained.
|
|
168
|
+
*/
|
|
169
|
+
export declare const STEAL_PAYLOAD_ACK_SLOT_OFFSET_U32: number;
|
|
170
|
+
/**
|
|
171
|
+
* Host-owned liveness mask for stealing consumers. A dead claimant may leave
|
|
172
|
+
* its WANT word set forever; survivors ignore WANT from consumers whose bit is
|
|
173
|
+
* clear here. This preserves single-writer ownership of every WANT word.
|
|
174
|
+
*/
|
|
175
|
+
export declare const STEAL_LIVE_SLOT_OFFSET_U32: number;
|
|
153
176
|
export declare const HEADER_U32_LENGTH: number;
|
|
154
177
|
export declare const HEADER_BYTE_LENGTH: number;
|
|
155
178
|
export declare const makeTask: () => Task;
|
|
@@ -168,7 +191,7 @@ type ResolveHostOptions = {
|
|
|
168
191
|
* - encode/decode are not re-entrant; payload codec uses a shared scratch buffer.
|
|
169
192
|
*/
|
|
170
193
|
export type Lock2 = ReturnType<typeof lock2>;
|
|
171
|
-
export declare const lock2: ({ headers, headerSlotStrideU32, LockBoundSector, payload, payloadConfig, payloadSector, textCompat, resultList, toSentList, recycleList, }: {
|
|
194
|
+
export declare const lock2: ({ headers, headerSlotStrideU32, LockBoundSector, payload, payloadConfig, payloadSector, textCompat, resultList, toSentList, recycleList, processBoundary, consumers, consumerId, regionLanes, }: {
|
|
172
195
|
headers?: SharedBufferSource;
|
|
173
196
|
headerSlotStrideU32?: number;
|
|
174
197
|
LockBoundSector?: SharedBufferSource;
|
|
@@ -179,6 +202,17 @@ export declare const lock2: ({ headers, headerSlotStrideU32, LockBoundSector, pa
|
|
|
179
202
|
toSentList?: RingQueue<Task>;
|
|
180
203
|
resultList?: RingQueue<Task>;
|
|
181
204
|
recycleList?: RingQueue<Task>;
|
|
205
|
+
processBoundary?: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Number of consumer endpoints sharing this lock. `1` (default) keeps the
|
|
208
|
+
* classic single-consumer path. `> 1` enables region-Dekker work stealing and
|
|
209
|
+
* is only valid on a host->worker submit lock, never on a return lock.
|
|
210
|
+
*/
|
|
211
|
+
consumers?: number;
|
|
212
|
+
/** This endpoint's id, `0..consumers-1`. Priority is fixed by id. */
|
|
213
|
+
consumerId?: number;
|
|
214
|
+
/** Lanes claimed per Dekker handshake. Paper rule: `slots / regionLanes >= consumers + 1`. */
|
|
215
|
+
regionLanes?: number;
|
|
182
216
|
}) => {
|
|
183
217
|
enlist: (task: Task) => true;
|
|
184
218
|
encode: (task: Task, state?: number) => boolean;
|
|
@@ -197,6 +231,7 @@ export declare const lock2: ({ headers, headerSlotStrideU32, LockBoundSector, pa
|
|
|
197
231
|
getPendingFrameCount: () => number;
|
|
198
232
|
getPendingPromiseCount: () => number;
|
|
199
233
|
resetPendingState: () => void;
|
|
234
|
+
deactivateStealConsumer: (id: number) => boolean;
|
|
200
235
|
takeDeferredCount: () => number;
|
|
201
236
|
setPromiseHandler: (handler?: PromisePayloadHandler) => void;
|
|
202
237
|
};
|