-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
doc: deprecate buffer.slice
#41596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc: deprecate buffer.slice
#41596
Conversation
|
An entry in https://github.com/nodejs/node/blob/master/doc/api/deprecations.md should also be added. |
482b28b to
d1f4857
Compare
|
Done, thanks. |
|
Maybe relevant: I noticed that |
jasnell
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally +1 on this. The one downside is that whenever a Buffer is used transparently as a Uint8Array users could still end up using slice() without realizing that there's a material difference between those. It might make sense eventually to make this a runtime deprecation or emit a warning.
|
@aduh95 TIL that issue titles support markdown :O @vweevers if that is a concern we can override (Edit, looking at V8 this is subarray https://source.chromium.org/chromium/chromium/src/+/main:v8/src/builtins/typed-array-subarray.tq?q=subarray&ss=chromium%2Fchromium%2Fsrc and here is some of the logic https://source.chromium.org/chromium/chromium/src/+/main:v8/src/builtins/typed-array-subarray.tq?q=subarray&ss=chromium%2Fchromium%2Fsrc if this is a concern we can run benchmarks) |
|
@jasnell Ideally I'll follow this up with a runtime warning if |
mcollina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm -1 for this deprecation. buffer.slice() is used kind of everywhere.
7365c66 to
79621a5
Compare
|
I believe the subsystem in the commit message should If proposal-rm-builtin-subclassing ever goes through, I've also noticed performance regressions when trying to replace |
|
I think |
Which is a good reason not to runtime-deprecate this, but how does the frequency of use affect doc deprecations? |
mcollina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for a doc-deprecation but hard -1 for anything further. We would need to support this forever.
I’m wondering how bad it would be if we did |
|
Hey, just pre-emptively putting "blocked" on this so we don't land this without checking that the performance doesn't regress with I don't think we can ever runtime deprecate it either but we can print a warning with |
9bfde1f to
a99e537
Compare
Why not flip that... make |
|
@jasnell Sure, that’s the same thing. It doesn’t really matter whether it’s |
aduh95
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Whoever lands this, please update subsystem in the commit messages:
doc: deprecate `buffer.slice`
benchmark: add `subarray` to `buffer-slice`
buffer: alias `subarray` and `slice`
|
@benjamingr Made the PR: #41628 |
|
Landed in 290911b...3d23d62 |
You mean "Node.js doubles the performance of |
Opening a PR to have the discussion about this particular idea (doc-deprecating buffer.slice).
References: #41588
For the why -
buffer.slice()returns a mutable slice whereastypedArray.slice()andarray.slice()return a copy. This is confusing behavior and is the result of buffers predating Uint8Array availability.cc @addaleax @jasnell @sindresorhus @nodejs/buffer
Also ccing some people who are usually helpful at giving useful comments when I make PRs that touch docs: @Trott @aduh95 @VoltrexMaster