@naturalcycles/nodejs-lib 13.19.0 → 13.21.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/csv/transformToCSV.js +1 -0
- package/dist/stream/ndjson/transformJsonParse.js +3 -0
- package/dist/stream/ndjson/transformToNDJson.js +1 -0
- package/dist/stream/transform/transformMap.d.ts +5 -2
- package/dist/stream/transform/transformMap.js +2 -2
- package/dist/stream/transform/transformSplit.js +3 -0
- package/package.json +1 -1
- package/src/csv/transformToCSV.ts +1 -0
- package/src/stream/ndjson/transformJsonParse.ts +3 -0
- package/src/stream/ndjson/transformToNDJson.ts +1 -0
- package/src/stream/transform/transformMap.ts +6 -3
- package/src/stream/transform/transformSplit.ts +3 -0
|
@@ -21,6 +21,9 @@ function transformJsonParse(opt = {}) {
|
|
|
21
21
|
return new node_stream_1.Transform({
|
|
22
22
|
writableObjectMode: false,
|
|
23
23
|
readableObjectMode: true,
|
|
24
|
+
// highWatermark increased, because it's proven to be faster: https://github.com/nodejs/node/pull/52037
|
|
25
|
+
// todo: it'll be default in Node 22, then we can remove this
|
|
26
|
+
writableHighWaterMark: 64 * 1024,
|
|
24
27
|
transform(chunk, _, cb) {
|
|
25
28
|
try {
|
|
26
29
|
const data = JSON.parse(chunk, reviver);
|
|
@@ -18,7 +18,10 @@ export interface TransformMapOptions<IN = any, OUT = IN> {
|
|
|
18
18
|
/**
|
|
19
19
|
* Number of concurrently pending promises returned by `mapper`.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
21
|
+
* Default is 32.
|
|
22
|
+
* It was recently changed up from 16, after some testing that shown that
|
|
23
|
+
* for simple low-cpu mapper functions 32 produces almost 2x throughput.
|
|
24
|
+
* For example, in scenarios like streaming a query from Datastore.
|
|
22
25
|
*/
|
|
23
26
|
concurrency?: number;
|
|
24
27
|
/**
|
|
@@ -83,7 +86,7 @@ export interface TransformMapStatsSummary extends TransformMapStats {
|
|
|
83
86
|
*
|
|
84
87
|
* Only works in objectMode (due to through2Concurrent).
|
|
85
88
|
*
|
|
86
|
-
* Concurrency defaults to
|
|
89
|
+
* Concurrency defaults to 32.
|
|
87
90
|
*
|
|
88
91
|
* If an Array is returned by `mapper` - it will be flattened and multiple results will be emitted from it. Tested by Array.isArray().
|
|
89
92
|
*/
|
|
@@ -15,12 +15,12 @@ const stream_util_1 = require("../stream.util");
|
|
|
15
15
|
*
|
|
16
16
|
* Only works in objectMode (due to through2Concurrent).
|
|
17
17
|
*
|
|
18
|
-
* Concurrency defaults to
|
|
18
|
+
* Concurrency defaults to 32.
|
|
19
19
|
*
|
|
20
20
|
* If an Array is returned by `mapper` - it will be flattened and multiple results will be emitted from it. Tested by Array.isArray().
|
|
21
21
|
*/
|
|
22
22
|
function transformMap(mapper, opt = {}) {
|
|
23
|
-
const { concurrency =
|
|
23
|
+
const { concurrency = 32, predicate, // we now default to "no predicate" (meaning pass-everything)
|
|
24
24
|
errorMode = js_lib_1.ErrorMode.THROW_IMMEDIATELY, flattenArrayOutput, onError, onDone, metric = 'stream', logger = console, } = opt;
|
|
25
25
|
const started = Date.now();
|
|
26
26
|
let index = -1;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformSplit = void 0;
|
|
4
|
+
// https://github.com/max-mapper/binary-split
|
|
5
|
+
// todo: test its newer version that doesn't have `through2` dependency
|
|
6
|
+
// todo: test writableHighWaterMark of 64k
|
|
4
7
|
const _binarySplit = require('binary-split');
|
|
5
8
|
/**
|
|
6
9
|
* Input: stream (objectMode=false) of arbitrary string|Buffer chunks, like when read from fs
|
package/package.json
CHANGED
|
@@ -35,6 +35,9 @@ export function transformJsonParse<OUT = any>(
|
|
|
35
35
|
return new Transform({
|
|
36
36
|
writableObjectMode: false,
|
|
37
37
|
readableObjectMode: true,
|
|
38
|
+
// highWatermark increased, because it's proven to be faster: https://github.com/nodejs/node/pull/52037
|
|
39
|
+
// todo: it'll be default in Node 22, then we can remove this
|
|
40
|
+
writableHighWaterMark: 64 * 1024,
|
|
38
41
|
transform(chunk: string, _, cb) {
|
|
39
42
|
try {
|
|
40
43
|
const data = JSON.parse(chunk, reviver)
|
|
@@ -40,7 +40,10 @@ export interface TransformMapOptions<IN = any, OUT = IN> {
|
|
|
40
40
|
/**
|
|
41
41
|
* Number of concurrently pending promises returned by `mapper`.
|
|
42
42
|
*
|
|
43
|
-
*
|
|
43
|
+
* Default is 32.
|
|
44
|
+
* It was recently changed up from 16, after some testing that shown that
|
|
45
|
+
* for simple low-cpu mapper functions 32 produces almost 2x throughput.
|
|
46
|
+
* For example, in scenarios like streaming a query from Datastore.
|
|
44
47
|
*/
|
|
45
48
|
concurrency?: number
|
|
46
49
|
|
|
@@ -117,7 +120,7 @@ export interface TransformMapStatsSummary extends TransformMapStats {
|
|
|
117
120
|
*
|
|
118
121
|
* Only works in objectMode (due to through2Concurrent).
|
|
119
122
|
*
|
|
120
|
-
* Concurrency defaults to
|
|
123
|
+
* Concurrency defaults to 32.
|
|
121
124
|
*
|
|
122
125
|
* If an Array is returned by `mapper` - it will be flattened and multiple results will be emitted from it. Tested by Array.isArray().
|
|
123
126
|
*/
|
|
@@ -126,7 +129,7 @@ export function transformMap<IN = any, OUT = IN>(
|
|
|
126
129
|
opt: TransformMapOptions<IN, OUT> = {},
|
|
127
130
|
): TransformTyped<IN, OUT> {
|
|
128
131
|
const {
|
|
129
|
-
concurrency =
|
|
132
|
+
concurrency = 32,
|
|
130
133
|
predicate, // we now default to "no predicate" (meaning pass-everything)
|
|
131
134
|
errorMode = ErrorMode.THROW_IMMEDIATELY,
|
|
132
135
|
flattenArrayOutput,
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { TransformTyped } from '../stream.model'
|
|
2
2
|
|
|
3
|
+
// https://github.com/max-mapper/binary-split
|
|
4
|
+
// todo: test its newer version that doesn't have `through2` dependency
|
|
5
|
+
// todo: test writableHighWaterMark of 64k
|
|
3
6
|
const _binarySplit = require('binary-split')
|
|
4
7
|
|
|
5
8
|
/**
|