-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Faster buffer slice using subarray() #2777
Conversation
/cc @trevnorris |
This changes the behaviour on non-numeric arguments. For example, |
Can you change up the commits so the first commit only contains the performance improvement? That is a minor change that we can land on v4. But the additions of throwing for out of range are a major change. |
Now the range checks are not valid (well, as they were not valid before). See #2668. This shouldn't stop this PR, because it's a separate issue. |
Yeah. If anything I'd like to get the performance fix in so it can land on the v4.x branch asap. we can discuss edge cases of handling range checks afterwards. |
20a591f
to
1f91ea3
Compare
It was already separated but I added the new string tests to the first one. Should I make a new PR for out-of-range commits or push behind? |
|
||
return binding.slice(this, start, end); | ||
var buffer = this.subarray(start, end); | ||
buffer.__proto__ = Buffer.prototype; |
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.
Please use Object.setPrototypeOf
1f91ea3
to
4867e3c
Compare
New PR please. Will make it easier to track and merge to other branches. |
LGTM |
LGTM if passes CI.
|
@@ -549,33 +549,10 @@ Buffer.prototype.toJSON = function() { | |||
}; | |||
|
|||
|
|||
// TODO(trevnorris): currently works like Array.prototype.slice(), which | |||
// doesn't follow the new standard for throwing on out of range indexes. |
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.
Why removing this comment? The behavior wasn't changed.
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.
Removed because initially the commit included the TODO.
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.
Thanks for noticing this @ChALkeR
Looking back, I put this in over 2 years ago (3a2f273) when I was attempting to be more strict with how arguments were handled. Now that we've been forced to use typed arrays it's safe to say that the original intention of this comment is dead. It's fine to leave it removed.
Oop, and just saw that it was added back. That's cool to. Maybe we should get some feedback about whether it should throw. I dunno anymore.
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.
@trevnorris That's out of scope of this PR =).
Btw, in that CI even the linter blew up on the Jenkins side.
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.
Yeah. The tests look fine to me. Going to land it.
benchmark/buffer-slice: 40% benchmark/buffer-creation (pool): 25%
4867e3c
to
47abd16
Compare
Use the built-in Typed Array method subarray() to improve performance of Buffer#slice(). Benchmark improvements: benchmark/buffer-slice: 40% benchmark/buffer-creation (pool): 25% Additional tests also added. PR-URL: #2777 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Thanks. Landed in e7a3ca3 with minor commit message change. |
Use the built-in Typed Array method subarray() to improve performance of Buffer#slice(). Benchmark improvements: benchmark/buffer-slice: 40% benchmark/buffer-creation (pool): 25% Additional tests also added. PR-URL: #2777 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
My performance patch for subarray landed in v8: https://codereview.chromium.org/1331993004 |
Notable changes: * buffer: - Buffers are now created in JavaScript, rather than C++. This increases the speed of buffer creation (Trevor Norris) nodejs#2866. - `Buffer#slice()` now uses `Uint8Array#subarray()` internally, increasing `slice()` performance (Karl Skomski) nodejs#2777. * fs: - `fs.utimes()` now properly converts numeric strings, `NaN`, and `Infinity` (Yazhong Liu) nodejs#2387. - `fs.WriteStream` now implements `_writev`, allowing for super-fast bulk writes (Ron Korving) nodejs#2167. * http: Fixed an issue with certain `write()` sizes causing errors when using `http.request()` (Fedor Indutny) nodejs#2824. * npm: Upgrade to version 2.14.3, see https://github.com/npm/npm/releases/tag/v2.14.3 for more details (Kat Marchán) nodejs#2822. * src: V8 cpu profiling no longer erroneously shows idle time (Oleksandr Chekhovskyi) nodejs#2324. * v8: Lateral upgrade to 4.5.103.33 from 4.5.103.30, contains minor fixes (Ali Ijaz Sheikh) nodejs#2870. - This fixes a previously known bug where some computed object shorthand properties did not work correctly (nodejs#2507). Refs: nodejs#2844 PR-URL: nodejs#2889
Notable changes: * buffer: - Buffers are now created in JavaScript, rather than C++. This increases the speed of buffer creation (Trevor Norris) #2866. - `Buffer#slice()` now uses `Uint8Array#subarray()` internally, increasing `slice()` performance (Karl Skomski) #2777. * fs: - `fs.utimes()` now properly converts numeric strings, `NaN`, and `Infinity` (Yazhong Liu) #2387. - `fs.WriteStream` now implements `_writev`, allowing for super-fast bulk writes (Ron Korving) #2167. * http: Fixed an issue with certain `write()` sizes causing errors when using `http.request()` (Fedor Indutny) #2824. * npm: Upgrade to version 2.14.3, see https://github.com/npm/npm/releases/tag/v2.14.3 for more details (Kat Marchán) #2822. * src: V8 cpu profiling no longer erroneously shows idle time (Oleksandr Chekhovskyi) #2324. * v8: Lateral upgrade to 4.5.103.33 from 4.5.103.30, contains minor fixes (Ali Ijaz Sheikh) #2870. - This fixes a previously known bug where some computed object shorthand properties did not work correctly (#2507). Refs: #2844 PR-URL: #2889
src: use subarray() in Buffer.slice() for speedup
src: throw on out-of-range args in Buffer.slice
Only changed tests that passed out-of-range args