knitting 0.1.63 → 0.1.73
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/README.md +623 -342
- package/knitting.browser.d.ts +3 -1
- package/knitting.browser.js +1 -1
- package/knitting.d.ts +3 -1
- package/knitting.js +2 -1
- package/map.md +0 -6
- package/package.json +10 -5
- package/prebuilds/darwin-arm64-node-127/knitting_buffer_pointer.node +0 -0
- package/prebuilds/darwin-arm64-node-127/knitting_doorbell.node +0 -0
- package/prebuilds/darwin-arm64-node-137/knitting_buffer_pointer.node +0 -0
- package/prebuilds/darwin-arm64-node-137/knitting_doorbell.node +0 -0
- package/prebuilds/darwin-x64-node-127/knitting_buffer_pointer.node +0 -0
- package/prebuilds/darwin-x64-node-127/knitting_doorbell.node +0 -0
- package/prebuilds/darwin-x64-node-137/knitting_buffer_pointer.node +0 -0
- package/prebuilds/darwin-x64-node-137/knitting_doorbell.node +0 -0
- package/prebuilds/linux-x64-node-127/knitting_buffer_pointer.node +0 -0
- package/prebuilds/linux-x64-node-127/knitting_doorbell.node +0 -0
- package/prebuilds/linux-x64-node-137/knitting_buffer_pointer.node +0 -0
- package/prebuilds/linux-x64-node-137/knitting_doorbell.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_doorbell.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_doorbell.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-native-addons.ts +5 -0
- package/shared-memory.d.ts +3 -0
- package/shared-memory.js +3 -0
- package/src/api.js +158 -71
- package/src/common/with-resolvers.js +2 -5
- package/src/common/worker-runtime.d.ts +7 -0
- package/src/common/worker-runtime.js +7 -0
- package/src/connections/buffer-reference.d.ts +10 -36
- package/src/connections/buffer-reference.js +15 -170
- package/src/connections/node-addons.d.ts +1 -1
- package/src/connections/node-addons.js +11 -1
- package/src/connections/shared-array-buffer-payload.d.ts +7 -0
- package/src/connections/shared-array-buffer-payload.js +27 -11
- package/src/debug/gate.js +1 -1
- package/src/debug/handle.d.ts +6 -1
- package/src/debug/handle.js +14 -6
- package/src/error.d.ts +9 -0
- package/src/error.js +16 -2
- package/src/knitting_buffer_pointer.cc +57 -2
- package/src/knitting_doorbell.cc +220 -0
- package/src/memory/knitting-body.d.ts +44 -0
- package/src/memory/knitting-body.js +51 -0
- package/src/memory/knitting-buffer-http.d.ts +116 -0
- package/src/memory/knitting-buffer-http.js +255 -0
- package/src/memory/knitting-buffer.d.ts +250 -0
- package/src/memory/knitting-buffer.js +695 -0
- package/src/memory/lazy-region-registry.d.ts +83 -0
- package/src/memory/lazy-region-registry.js +355 -0
- package/src/memory/lock.d.ts +80 -15
- package/src/memory/lock.js +473 -139
- package/src/memory/payloadCodec.d.ts +18 -2
- package/src/memory/payloadCodec.js +340 -76
- package/src/memory/regionRegistry.d.ts +6 -0
- package/src/memory/regionRegistry.js +125 -240
- package/src/memory/shared-buffer-io.d.ts +7 -0
- package/src/memory/shared-buffer-io.js +34 -8
- package/src/permission/protocol.d.ts +1 -0
- package/src/permission/protocol.js +8 -3
- package/src/runtime/deno-doorbell.d.ts +26 -0
- package/src/runtime/deno-doorbell.js +117 -0
- package/src/runtime/dispatcher.d.ts +13 -6
- package/src/runtime/dispatcher.js +101 -63
- package/src/runtime/host-arg-arena.d.ts +3 -0
- package/src/runtime/host-arg-arena.js +16 -0
- package/src/runtime/inline-executor.js +2 -1
- package/src/runtime/node-doorbell.d.ts +14 -0
- package/src/runtime/node-doorbell.js +84 -0
- package/src/runtime/pool.d.ts +30 -15
- package/src/runtime/pool.js +199 -151
- package/src/runtime/process-worker.d.ts +9 -0
- package/src/runtime/process-worker.js +32 -3
- package/src/runtime/tx-queue.d.ts +4 -6
- package/src/runtime/tx-queue.js +63 -48
- package/src/runtime/worker-common.d.ts +7 -0
- package/src/runtime/worker-common.js +28 -2
- package/src/types.d.ts +66 -78
- package/src/worker/loop.js +95 -60
- package/src/worker/rx-queue.d.ts +2 -3
- package/src/worker/rx-queue.js +34 -40
- package/src/worker/safety/index.d.ts +1 -1
- package/src/worker/safety/index.js +1 -1
- package/src/worker/safety/process.d.ts +2 -0
- package/src/worker/safety/process.js +8 -1
- package/src/worker/safety/startup.js +11 -6
- package/src/worker/shared-return.d.ts +9 -0
- package/src/worker/shared-return.js +22 -0
- package/src/worker/task-loader.js +1 -2
- package/src/worker/timers.d.ts +2 -6
- package/src/worker/timers.js +39 -22
- package/unsafe.d.ts +2 -1
- package/unsafe.js +2 -1
package/src/runtime/pool.d.ts
CHANGED
|
@@ -2,28 +2,29 @@ import { createHostTxQueue } from "./tx-queue.js";
|
|
|
2
2
|
import { type ProcessSharedMemoryBacking, type ProcessStealMemoryLayout, type ResolvedProcessSharedMemorySettings } from "./process-worker.js";
|
|
3
3
|
import { type Sab } from "../ipc/transport/shared-memory.js";
|
|
4
4
|
import { ChannelHandler, type DispatcherCheck } from "./dispatcher.js";
|
|
5
|
-
import {
|
|
5
|
+
import type { DenoCompletionDoorbell } from "./deno-doorbell.js";
|
|
6
|
+
import { lock2, type StealClaimDiscipline, type Task } from "../memory/lock.js";
|
|
6
7
|
import "../memory/payloadCodec.js";
|
|
7
8
|
import type { DebugOptions, DispatcherSettings, LockBuffers, WorkerContext, WorkerData, WorkerSettings } from "../types.js";
|
|
8
9
|
import "../worker/loop.js";
|
|
9
10
|
import { type PayloadBufferOptions } from "../memory/payload-config.js";
|
|
11
|
+
/** Build the shared submit and private return buffers for a stealing pool. */
|
|
12
|
+
export declare const resolveStealRegionLanes: (consumers: number) => number;
|
|
10
13
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* any lane settles the right promise.
|
|
15
|
-
*
|
|
16
|
-
* Region width follows paper §6.1: the largest power-of-two `g` leaving a spare
|
|
17
|
-
* region for a delayed claimant (`slots / g >= consumers + 1`). At 32 slots that
|
|
18
|
-
* caps how wide a region can be well before it caps the worker count.
|
|
14
|
+
* Return the widest region allowed by the selected claim discipline. Only
|
|
15
|
+
* Dekker needs a region per consumer; `ticket` has no regions at all and uses
|
|
16
|
+
* the width purely as a claim batch size.
|
|
19
17
|
*/
|
|
20
|
-
export declare const
|
|
18
|
+
export declare const resolveMaxStealRegionLanes: (consumers: number, stealClaim?: StealClaimDiscipline) => number;
|
|
21
19
|
/** Maximum claimants that leave the protocol's required spare region. */
|
|
22
20
|
export declare const MAX_STEAL_CONSUMERS: number;
|
|
23
|
-
export declare const createStealPoolBuffers: ({ threads, payload, regionLanes, abortSignalCapacity, usesAbortSignal, processWorker, }: {
|
|
21
|
+
export declare const createStealPoolBuffers: ({ threads, payload, sharedArgs, regionLanes, stealClaim, abortSignalCapacity, usesAbortSignal, processWorker, }: {
|
|
24
22
|
threads: number;
|
|
25
23
|
payload?: PayloadBufferOptions;
|
|
24
|
+
/** Hand large arguments to workers as borrowed regions. See `unsafe.SharedArgs`. */
|
|
25
|
+
sharedArgs?: boolean;
|
|
26
26
|
regionLanes?: number;
|
|
27
|
+
stealClaim?: StealClaimDiscipline;
|
|
27
28
|
abortSignalCapacity?: number;
|
|
28
29
|
usesAbortSignal?: boolean;
|
|
29
30
|
processWorker?: {
|
|
@@ -53,6 +54,7 @@ export declare const createStealPoolBuffers: ({ threads, payload, regionLanes, a
|
|
|
53
54
|
activeRejectPlaceholder?: Task["reject"];
|
|
54
55
|
}) => () => number;
|
|
55
56
|
waitForHostChange: (timeoutMs?: number) => import("../memory/lock.js").WaitAsyncResult | undefined;
|
|
57
|
+
armHostNotifier: () => boolean;
|
|
56
58
|
setHostWaiterArmed: (armed: boolean) => void;
|
|
57
59
|
hasPendingFrames: () => boolean;
|
|
58
60
|
getPendingFrameCount: () => number;
|
|
@@ -82,6 +84,7 @@ export declare const createStealPoolBuffers: ({ threads, payload, regionLanes, a
|
|
|
82
84
|
activeRejectPlaceholder?: Task["reject"];
|
|
83
85
|
}) => () => number;
|
|
84
86
|
waitForHostChange: (timeoutMs?: number) => import("../memory/lock.js").WaitAsyncResult | undefined;
|
|
87
|
+
armHostNotifier: () => boolean;
|
|
85
88
|
setHostWaiterArmed: (armed: boolean) => void;
|
|
86
89
|
hasPendingFrames: () => boolean;
|
|
87
90
|
getPendingFrameCount: () => number;
|
|
@@ -92,24 +95,26 @@ export declare const createStealPoolBuffers: ({ threads, payload, regionLanes, a
|
|
|
92
95
|
setPromiseHandler: (handler?: import("../memory/lock.js").PromisePayloadHandler) => void;
|
|
93
96
|
}[];
|
|
94
97
|
sharedQueue: {
|
|
95
|
-
|
|
98
|
+
close: (reason: unknown) => void;
|
|
99
|
+
rejectAll: (reason: unknown) => void;
|
|
96
100
|
hasPendingFrames: () => boolean;
|
|
97
101
|
txIdle: () => boolean;
|
|
98
102
|
completeFrame: () => number;
|
|
99
103
|
waitForCompletion: (onWake: () => void, timeoutMs?: number) => boolean;
|
|
104
|
+
armCompletionNotifier: () => boolean;
|
|
100
105
|
setCompletionWaiterArmed: (armed: boolean) => void;
|
|
101
|
-
setReturnHooks: (lane: number, hooks: (import("../connections/buffer-reference.js").BufferReferenceReturnHooks | ((token: bigint) => void)) | undefined) => void;
|
|
102
106
|
enqueue: (functionID: number, timeout?: import("../types.js").TaskTimeout, abortSignal?: import("../types.js").AbortSignalOption) => (rawArgs: unknown) => Promise<never> | import("../common/with-resolvers.js").PromiseWithMaybeReject<unknown>;
|
|
103
107
|
flushToWorker: () => boolean;
|
|
104
108
|
enqueueKnown: (task: Task) => boolean;
|
|
105
109
|
settlePromisePayload: (task: Task, isRejected: boolean, value: unknown) => boolean;
|
|
106
110
|
};
|
|
107
111
|
regionLanes: number;
|
|
112
|
+
stealClaim: "dekker" | "ticket";
|
|
108
113
|
processMemory: ProcessStealMemoryLayout;
|
|
109
114
|
abortSignalSAB: SharedArrayBuffer | import("../types.js").SharedBufferRegion;
|
|
110
115
|
abortSignalMax: number;
|
|
111
116
|
};
|
|
112
|
-
export declare const spawnWorkerContext: ({ list, ids, names, sab, thread, debug, hostDebug, totalNumberOfThread, workerCount, source, at, workerOptions, workerExecArgv, permission, host, payload,
|
|
117
|
+
export declare const spawnWorkerContext: ({ list, ids, names, sab, thread, debug, debugEpoch, hostDebug, totalNumberOfThread, workerCount, source, at, workerOptions, workerExecArgv, requestedExecArgv, permission, host, payload, sharedBytesEnabled, abortSignalCapacity, usesAbortSignal, sharedChannelHandler, denoCompletionDoorbell, stealPool, }: {
|
|
113
118
|
list: string[];
|
|
114
119
|
ids: number[];
|
|
115
120
|
names: string[];
|
|
@@ -117,6 +122,7 @@ export declare const spawnWorkerContext: ({ list, ids, names, sab, thread, debug
|
|
|
117
122
|
sab?: Sab;
|
|
118
123
|
thread: number;
|
|
119
124
|
debug?: DebugOptions;
|
|
125
|
+
debugEpoch?: number;
|
|
120
126
|
hostDebug?: (message: string) => void;
|
|
121
127
|
totalNumberOfThread: number;
|
|
122
128
|
/**
|
|
@@ -128,10 +134,12 @@ export declare const spawnWorkerContext: ({ list, ids, names, sab, thread, debug
|
|
|
128
134
|
source?: string;
|
|
129
135
|
workerOptions?: WorkerSettings;
|
|
130
136
|
workerExecArgv?: string[];
|
|
137
|
+
/** The caller's own `workerExecArgv`, before defaults and filtering. */
|
|
138
|
+
requestedExecArgv?: string[];
|
|
131
139
|
permission?: WorkerData["permission"];
|
|
132
140
|
host?: DispatcherSettings;
|
|
133
141
|
payload?: PayloadBufferOptions;
|
|
134
|
-
|
|
142
|
+
sharedBytesEnabled?: boolean;
|
|
135
143
|
abortSignalCapacity?: number;
|
|
136
144
|
usesAbortSignal?: boolean;
|
|
137
145
|
/**
|
|
@@ -139,6 +147,8 @@ export declare const spawnWorkerContext: ({ list, ids, names, sab, thread, debug
|
|
|
139
147
|
* macro channel that runs all lane checks.
|
|
140
148
|
*/
|
|
141
149
|
sharedChannelHandler?: ChannelHandler;
|
|
150
|
+
/** Deno-only native callback shared by every thread worker in this pool. */
|
|
151
|
+
denoCompletionDoorbell?: DenoCompletionDoorbell;
|
|
142
152
|
/**
|
|
143
153
|
* Work-stealing wiring. When present the submit region, both host-side locks
|
|
144
154
|
* and the pending registry are owned by `createPool` and shared: every worker
|
|
@@ -155,6 +165,7 @@ export declare const spawnWorkerContext: ({ list, ids, names, sab, thread, debug
|
|
|
155
165
|
consumers: number;
|
|
156
166
|
consumerId: number;
|
|
157
167
|
regionLanes: number;
|
|
168
|
+
stealClaim?: StealClaimDiscipline;
|
|
158
169
|
abortSignalSAB?: LockBuffers["headers"];
|
|
159
170
|
abortSignalMax?: number;
|
|
160
171
|
processMemory?: ProcessStealMemoryLayout;
|
|
@@ -168,6 +179,10 @@ export declare const spawnWorkerContext: ({ list, ids, names, sab, thread, debug
|
|
|
168
179
|
processSharedMemoryBackings?: readonly ProcessSharedMemoryBacking[];
|
|
169
180
|
dispatcherCheck?: DispatcherCheck;
|
|
170
181
|
laneWake?: () => void;
|
|
182
|
+
laneAwake?: () => boolean;
|
|
171
183
|
bindSend?: (fn: () => void) => void;
|
|
184
|
+
bindCompletionWake?: (fn: () => void) => void;
|
|
185
|
+
processCompletionDoorbell?: boolean;
|
|
186
|
+
nodeCompletionDoorbell?: boolean;
|
|
172
187
|
});
|
|
173
188
|
export type CreateContext = WorkerContext;
|