@nxtedition/shared 1.0.10 → 1.0.12

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 CHANGED
@@ -4,9 +4,9 @@ A high-performance, thread-safe ring buffer for inter-thread communication in No
4
4
 
5
5
  ## Why
6
6
 
7
- Passing data between worker threads in Node.js typically involves structured cloning or transferring `ArrayBuffer` ownership. Structured cloning copies every byte — fine for occasional messages, but a bottleneck when streaming megabytes per second between threads. Transferable objects avoid the copy, but ownership transfer means the sender loses access, which complicates protocols that need to retain the data.
7
+ Passing data between worker threads in Node.js typically involves structured cloning or transferring `ArrayBuffer` ownership. Structured cloning copies every byte — fine for occasional messages, but a bottleneck when streaming megabytes per second between threads. Transferable objects avoid the copy, but each transfer still requires allocating a new `ArrayBuffer`, serializing the transfer list, and coordinating ownership between threads — overhead that adds up quickly in high-throughput scenarios.
8
8
 
9
- This ring buffer avoids both problems. A single `SharedArrayBuffer` is mapped into both threads. The writer appends messages by advancing a write pointer; the reader consumes them by advancing a read pointer. No copies, no ownership transfers, no cloning overhead. The pointers are coordinated with `Atomics` operations, and cache-line-aligned to prevent false sharing between CPU cores.
9
+ This ring buffer avoids these problems. A single `SharedArrayBuffer` is mapped into both threads. The writer appends messages by advancing a write pointer; the reader consumes them by advancing a read pointer. No copies, no ownership transfers, no cloning overhead. Because messages are stored inline in a contiguous buffer, data lives right where the protocol is rather than scattered across separately allocated `ArrayBuffer`s — keeping access patterns cache-friendly. The pointers are coordinated with `Atomics` operations, and cache-line-aligned to prevent false sharing between CPU cores.
10
10
 
11
11
  Reads are zero-copy: the reader callback receives a `DataView` directly into the shared buffer, so parsing can happen in-place without allocating intermediate buffers. Writes are batched — the write pointer is only published to the reader after a high-water mark is reached or the current event loop tick ends, drastically reducing the frequency of expensive atomic stores.
12
12
 
package/lib/index.js CHANGED
@@ -318,7 +318,7 @@ export function writer(
318
318
  // NOTE: This is unsafe as the user function can write beyond the reserved length.
319
319
  const dataLen = fn(data) - dataPos
320
320
 
321
- if (typeof dataLen !== 'number') {
321
+ if (!Number.isFinite(dataLen)) {
322
322
  throw new TypeError('"fn" must return the number of bytes written')
323
323
  }
324
324
  if (dataLen < 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/shared",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -27,5 +27,5 @@
27
27
  "rimraf": "^6.1.2",
28
28
  "typescript": "^5.9.3"
29
29
  },
30
- "gitHead": "43180e101ef8e6b579c60f24ab5329577627134e"
30
+ "gitHead": "80ace3245dc851f38a288b0c3b167ca0024f0469"
31
31
  }