placement-worker
Type Aliases
CacheEntryJob
type CacheEntryJob = object;Defined in: tar/src/placement-worker.ts:46
Unpack the tarball in a vlt cache entry file into target. The
worker reads the file itself, so the main thread never holds or
copies the body.
Type declaration
| Name | Type |
|---|---|
file | string |
format? | TarballFormat |
id | number |
kind | "cacheEntry" |
target | string |
PlacementJob
type PlacementJob =
| UnpackJob
| CacheEntryJob;Defined in: tar/src/placement-worker.ts:54
PlacementReply
type PlacementReply =
| {
id: number;
result: true;
}
| {
code: string;
error: string;
id: number;
stack: string;
}
| {
ready: true;
};Defined in: tar/src/placement-worker.ts:61
A worker's reply for job id: true once unpacked, or the message,
stack and errno code of the error thrown, which the pool rebuilds
into an Error so a worker failure looks like the inline call failing.
Type declaration
{
id: number;
result: true;
}
| Name | Type |
|---|---|
id | number |
result | true |
{
code: string;
error: string;
id: number;
stack: string;
}
| Name | Type |
|---|---|
code? | string |
error | string |
id | number |
stack? | string |
{
ready: true;
}
| Name | Type |
|---|---|
ready | true |
ReplyPort
type ReplyPort = object;Defined in: tar/src/placement-worker.ts:68
A port that takes a PlacementReply; the real one is parentPort.
Type declaration
| Name | Type |
|---|---|
postMessage | (reply) => void |
UnpackJob
type UnpackJob = object;Defined in: tar/src/placement-worker.ts:31
Unpack a tarball into target. The bytes arrive as an ArrayBuffer
transferred from the main thread.
Type declaration
| Name | Type |
|---|---|
buffer | ArrayBuffer |
byteLength | number |
byteOffset | number |
format? | TarballFormat |
id | number |
kind | "unpack" |
target | string |
Variables
__CODE_SPLIT_SCRIPT_NAME
const __CODE_SPLIT_SCRIPT_NAME: string;Defined in: tar/src/placement-worker.ts:25
Unpacking a tarball is synchronous work the main thread cannot
afford: inflating it, parsing it and writing its files. While the
main thread does that, no registry response is read, no manifest is
parsed and no node is placed in the graph. A PlacementPool runs
this script as a worker thread so several packages are unpacked at
once, across cores, and the main thread stays free to keep the
network busy.
Hardlinking a global store entry stays on the main thread: it is a fraction of a millisecond per package, and on a two-core machine the boot of the workers and the round trips never paid for themselves (measured: +48% on the placement phase of a warm install).
The build emits it as its own bundled file: the exported
__CODE_SPLIT_SCRIPT_NAME is the path to spawn (the source
.ts in dev and test, the built .js in the bundle), and
handleJob is the per-message handler, exported so it can be
tested without a live worker.
Functions
handleJob()
function handleJob(port, job): voidDefined in: tar/src/placement-worker.ts:73
Run one job and post the result (or its error) back.
Parameters
| Parameter | Type |
|---|---|
port | ReplyPort |
job | PlacementJob |
Returns
void