This should give a performance boost accross the board. Given that the old limit is a decod old and memory capacity has doubled many times since I think it is appropriate to slightly bump the default limit. PR-URL: https://github.com/nodejs/node/pull/52037 Refs: https://github.com/nodejs/node/pull/46608 Refs: https://github.com/nodejs/node/pull/50120 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
const {
|
|
MathFloor,
|
|
NumberIsInteger,
|
|
} = primordials;
|
|
const { validateInteger } = require('internal/validators');
|
|
|
|
const { ERR_INVALID_ARG_VALUE } = require('internal/errors').codes;
|
|
|
|
// TODO (fix): For some reason Windows CI fails with bigger hwm.
|
|
let defaultHighWaterMarkBytes = process.platform === 'win32' ? 16 * 1024 : 64 * 1024;
|
|
let defaultHighWaterMarkObjectMode = 16;
|
|
|
|
function highWaterMarkFrom(options, isDuplex, duplexKey) {
|
|
return options.highWaterMark != null ? options.highWaterMark :
|
|
isDuplex ? options[duplexKey] : null;
|
|
}
|
|
|
|
function getDefaultHighWaterMark(objectMode) {
|
|
return objectMode ? defaultHighWaterMarkObjectMode : defaultHighWaterMarkBytes;
|
|
}
|
|
|
|
function setDefaultHighWaterMark(objectMode, value) {
|
|
validateInteger(value, 'value', 0);
|
|
if (objectMode) {
|
|
defaultHighWaterMarkObjectMode = value;
|
|
} else {
|
|
defaultHighWaterMarkBytes = value;
|
|
}
|
|
}
|
|
|
|
function getHighWaterMark(state, options, duplexKey, isDuplex) {
|
|
const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
|
|
if (hwm != null) {
|
|
if (!NumberIsInteger(hwm) || hwm < 0) {
|
|
const name = isDuplex ? `options.${duplexKey}` : 'options.highWaterMark';
|
|
throw new ERR_INVALID_ARG_VALUE(name, hwm);
|
|
}
|
|
return MathFloor(hwm);
|
|
}
|
|
|
|
// Default value
|
|
return getDefaultHighWaterMark(state.objectMode);
|
|
}
|
|
|
|
module.exports = {
|
|
getHighWaterMark,
|
|
getDefaultHighWaterMark,
|
|
setDefaultHighWaterMark,
|
|
};
|