buffer: move SlowBuffer to EOL · nodejs/node@0579e0e · GitHub
Skip to content

Commit 0579e0e

Browse files
jasnellRafaelGSS
authored andcommitted
buffer: move SlowBuffer to EOL
`SlowBuffer` has been deprecated for many years now. Let's remove it. PR-URL: #58008 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 3d34c5f commit 0579e0e

23 files changed

Lines changed: 61 additions & 118 deletions

benchmark/buffers/buffer-iterate.js

Lines changed: 2 additions & 2 deletions

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

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

45
const types = [
56
'IntBE',
@@ -18,7 +19,7 @@ const bench = common.createBenchmark(main, {
1819
function main({ n, buf, type, byteLength }) {
1920
const buff = buf === 'fast' ?
2021
Buffer.alloc(8) :
21-
require('buffer').SlowBuffer(8);
22+
Buffer.allocUnsafeSlow(8);
2223
const fn = `read${type}`;
2324

2425
buff.writeDoubleLE(0, 0);

benchmark/buffers/buffer-read.js

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

45
const types = [
56
'BigUInt64LE',
@@ -27,7 +28,7 @@ const bench = common.createBenchmark(main, {
2728
function main({ n, buf, type }) {
2829
const buff = buf === 'fast' ?
2930
Buffer.alloc(8) :
30-
require('buffer').SlowBuffer(8);
31+
Buffer.allocUnsafeSlow(8);
3132
const fn = `read${type}`;
3233

3334
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 SlowBuffer = require('buffer').SlowBuffer;
3+
const { Buffer } = require('buffer');
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 = new SlowBuffer(1024);
11+
const slowBuf = Buffer.allocUnsafeSlow(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-
3+
const { Buffer } = require('buffer');
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-
require('buffer').SlowBuffer(8);
76+
Buffer.allocUnsafeSlow(8);
7777
const fn = `write${type}`;
7878

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

doc/api/buffer.md

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5340,28 +5340,6 @@ 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-
53655343
### Buffer constants
53665344

53675345
<!-- YAML
@@ -5494,11 +5472,11 @@ added: v5.10.0
54945472

54955473
Node.js can be started using the `--zero-fill-buffers` command-line option to
54965474
cause all newly-allocated `Buffer` instances to be zero-filled upon creation by
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.
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.
55025480

55035481
```console
55045482
$ node --zero-fill-buffers

doc/api/cli.md

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

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

31173116
## Environment variables
31183117

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

doc/api/deprecations.md

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

696696
<!-- YAML
697697
changes:
698+
- version: REPLACEME
699+
pr-url: https://github.com/nodejs/node/pull/58008
700+
description: End-of-Life.
698701
- version: REPLACEME
699702
pr-url: https://github.com/nodejs/node/pull/55175
700703
description: Runtime deprecation.
@@ -706,9 +709,9 @@ changes:
706709
description: Documentation-only deprecation.
707710
-->
708711

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

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

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

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

Lines changed: 4 additions & 3 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 { SlowBuffer } = require('node:buffer');
575+
const { Buffer } = require('node:buffer');
576576

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

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

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

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

doc/node.1

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)