Revert "buffer: move SlowBuffer to EOL" · nodejs/node@2e1d958 · GitHub
Skip to content

Commit 2e1d958

Browse files
panvaaduh95
authored andcommitted
Revert "buffer: move SlowBuffer to EOL"
This reverts commit 0579e0e PR-URL: #58211 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent fd37a14 commit 2e1d958

23 files changed

Lines changed: 118 additions & 61 deletions

benchmark/buffers/buffer-iterate.js

Lines changed: 2 additions & 2 deletions

benchmark/buffers/buffer-read-with-byteLength.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22
const common = require('../common.js');
3-
const { Buffer } = require('buffer');
43

54
const types = [
65
'IntBE',
@@ -19,7 +18,7 @@ const bench = common.createBenchmark(main, {
1918
function main({ n, buf, type, byteLength }) {
2019
const buff = buf === 'fast' ?
2120
Buffer.alloc(8) :
22-
Buffer.allocUnsafeSlow(8);
21+
require('buffer').SlowBuffer(8);
2322
const fn = `read${type}`;
2423

2524
buff.writeDoubleLE(0, 0);

benchmark/buffers/buffer-read.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22
const common = require('../common.js');
3-
const { Buffer } = require('buffer');
43

54
const types = [
65
'BigUInt64LE',
@@ -28,7 +27,7 @@ const bench = common.createBenchmark(main, {
2827
function main({ n, buf, type }) {
2928
const buff = buf === 'fast' ?
3029
Buffer.alloc(8) :
31-
Buffer.allocUnsafeSlow(8);
30+
require('buffer').SlowBuffer(8);
3231
const fn = `read${type}`;
3332

3433
buff.writeDoubleLE(0, 0);

benchmark/buffers/buffer-slice.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
22
const common = require('../common.js');
3-
const { Buffer } = require('buffer');
3+
const SlowBuffer = require('buffer').SlowBuffer;
44

55
const bench = common.createBenchmark(main, {
66
type: ['fast', 'slow', 'subarray'],
77
n: [1e6],
88
});
99

1010
const buf = Buffer.allocUnsafe(1024);
11-
const slowBuf = Buffer.allocUnsafeSlow(1024);
11+
const slowBuf = new SlowBuffer(1024);
1212

1313
function main({ n, type }) {
1414
const b = type === 'slow' ? slowBuf : buf;

benchmark/buffers/buffer-write.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common.js');
3-
const { Buffer } = require('buffer');
3+
44
const types = [
55
'BigUInt64LE',
66
'BigUInt64BE',
@@ -73,7 +73,7 @@ const byteLength = {
7373
function main({ n, buf, type }) {
7474
const buff = buf === 'fast' ?
7575
Buffer.alloc(8) :
76-
Buffer.allocUnsafeSlow(8);
76+
require('buffer').SlowBuffer(8);
7777
const fn = `write${type}`;
7878

7979
if (!/\d/.test(fn))

doc/api/buffer.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5340,6 +5340,28 @@ console.log(newBuf.toString('ascii'));
53405340
Because the Euro (``) sign is not representable in US-ASCII, it is replaced
53415341
with `?` in the transcoded `Buffer`.
53425342

5343+
### Class: `SlowBuffer`
5344+
5345+
<!-- YAML
5346+
deprecated: v6.0.0
5347+
-->
5348+
5349+
> Stability: 0 - Deprecated: Use [`Buffer.allocUnsafeSlow()`][] instead.
5350+
5351+
See [`Buffer.allocUnsafeSlow()`][]. This was never a class in the sense that
5352+
the constructor always returned a `Buffer` instance, rather than a `SlowBuffer`
5353+
instance.
5354+
5355+
#### `new SlowBuffer(size)`
5356+
5357+
<!-- YAML
5358+
deprecated: v6.0.0
5359+
-->
5360+
5361+
* `size` {integer} The desired length of the new `SlowBuffer`.
5362+
5363+
See [`Buffer.allocUnsafeSlow()`][].
5364+
53435365
### Buffer constants
53445366

53455367
<!-- YAML
@@ -5472,11 +5494,11 @@ added: v5.10.0
54725494

54735495
Node.js can be started using the `--zero-fill-buffers` command-line option to
54745496
cause all newly-allocated `Buffer` instances to be zero-filled upon creation by
5475-
default. Without the option, buffers created with [`Buffer.allocUnsafe()`][] and
5476-
[`Buffer.allocUnsafeSlow()`][] are not zero-filled. Use of this flag can have a
5477-
measurable negative impact on performance. Use the `--zero-fill-buffers` option
5478-
only when necessary to enforce that newly allocated `Buffer` instances cannot
5479-
contain old data that is potentially sensitive.
5497+
default. Without the option, buffers created with [`Buffer.allocUnsafe()`][],
5498+
[`Buffer.allocUnsafeSlow()`][], and `new SlowBuffer(size)` are not zero-filled.
5499+
Use of this flag can have a measurable negative impact on performance. Use the
5500+
`--zero-fill-buffers` option only when necessary to enforce that newly allocated
5501+
`Buffer` instances cannot contain old data that is potentially sensitive.
54805502

54815503
```console
54825504
$ node --zero-fill-buffers

doc/api/cli.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3111,7 +3111,8 @@ node --watch --watch-preserve-output test.js
31113111
added: v6.0.0
31123112
-->
31133113

3114-
Automatically zero-fills all newly allocated [`Buffer`][] instances.
3114+
Automatically zero-fills all newly allocated [`Buffer`][] and [`SlowBuffer`][]
3115+
instances.
31153116

31163117
## Environment variables
31173118

@@ -3886,6 +3887,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
38863887
[`ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX`]: errors.md#err_unsupported_typescript_syntax
38873888
[`NODE_OPTIONS`]: #node_optionsoptions
38883889
[`NO_COLOR`]: https://no-color.org
3890+
[`SlowBuffer`]: buffer.md#class-slowbuffer
38893891
[`Web Storage`]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API
38903892
[`WebSocket`]: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
38913893
[`YoungGenerationSizeFromSemiSpaceSize`]: https://chromium.googlesource.com/v8/v8.git/+/refs/tags/10.3.129/src/heap/heap.cc#328

doc/api/deprecations.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,6 @@ Type: End-of-Life
695695

696696
<!-- YAML
697697
changes:
698-
- version: v24.0.0
699-
pr-url: https://github.com/nodejs/node/pull/58008
700-
description: End-of-Life.
701698
- version: v24.0.0
702699
pr-url: https://github.com/nodejs/node/pull/55175
703700
description: Runtime deprecation.
@@ -709,9 +706,9 @@ changes:
709706
description: Documentation-only deprecation.
710707
-->
711708

712-
Type: End-of-Life
709+
Type: Runtime
713710

714-
The `SlowBuffer` class has been removed. Please use
711+
The [`SlowBuffer`][] class is deprecated. Please use
715712
[`Buffer.allocUnsafeSlow(size)`][] instead.
716713

717714
### DEP0031: `ecdh.setPublicKey()`
@@ -3921,6 +3918,7 @@ upon `require('node:module').builtinModules`.
39213918
[`ReadStream.open()`]: fs.md#class-fsreadstream
39223919
[`Server.getConnections()`]: net.md#servergetconnectionscallback
39233920
[`Server.listen({fd: <number>})`]: net.md#serverlistenhandle-backlog-callback
3921+
[`SlowBuffer`]: buffer.md#class-slowbuffer
39243922
[`String.prototype.toWellFormed`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toWellFormed
39253923
[`WriteStream.open()`]: fs.md#class-fswritestream
39263924
[`assert.CallTracker`]: assert.md#class-assertcalltracker

doc/contributing/writing-and-running-benchmarks.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ the code inside the `main` function if it's more than just declaration.
572572
```js
573573
'use strict';
574574
const common = require('../common.js');
575-
const { Buffer } = require('node:buffer');
575+
const { SlowBuffer } = require('node:buffer');
576576

577577
const configs = {
578578
// Number of operations, specified here so they show up in the report.
@@ -603,11 +603,10 @@ function main(conf) {
603603
bench.start();
604604

605605
// Do operations here
606+
const BufferConstructor = conf.type === 'fast' ? Buffer : SlowBuffer;
606607

607608
for (let i = 0; i < conf.n; i++) {
608-
conf.type === 'fast' ?
609-
Buffer.allocUnsafe(conf.size) :
610-
Buffer.allocUnsafeSlow(conf.size);
609+
new BufferConstructor(conf.size);
611610
}
612611

613612
// End the timer, pass in the number of operations

doc/node.1

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)