buffer: improve toJSON() performance#10895
Conversation
819dc38 to
a437f73
Compare
| }); | ||
|
|
||
| function main(conf) { | ||
| var n = +conf.n; |
There was a problem hiding this comment.
why not use let or const for n and buf to maintain consistency across the codebase
There was a problem hiding this comment.
Personally I'd rather just stick to var in benchmark code for the forseeable future. Having issues with let and const in node core code has left a bit of a "bad taste." While it might seem moot in benchmark code, I'd rather not have to worry about deopts making my benchmarks run unnecessarily longer.
There was a problem hiding this comment.
In addition to what @mscdex said, the current position on const/let over var is "only in code where performance doesn't matter". I'd say it makes more sense for benchmarks/ to be consistent with lib/ than test/.
There was a problem hiding this comment.
oh that was something new! Thanks!
| data: Array.prototype.slice.call(this, 0) | ||
| }; | ||
| if (this.length) { | ||
| const data = []; |
There was a problem hiding this comment.
Is this faster than using new Array(this.length)?
There was a problem hiding this comment.
It is until appropriate backports to V8 5.4 are made. I've just decided to go ahead and use this method. See this issue for more information.
| data[i] = this[i]; | ||
| return { type: 'Buffer', data }; | ||
| } else { | ||
| return { type: 'Buffer', data: [] }; |
There was a problem hiding this comment.
Why the special case at all? The loop would run 0 times if length is 0, and you would get exactly the output you want. I doubt performance would be any different, would it?
There was a problem hiding this comment.
Unless the difference is really noticeable, I think I'd rather keep this simple and drop the if statement as @ronkorving said.
There was a problem hiding this comment.
There is a noticeable performance difference, otherwise I wouldn't have bothered. Without checking the IR explicitly, it probably has to do with setting up the loop or similar.
|
Landed in 9fcd842. |
PR-URL: #10895 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#10895 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#10895 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#10895 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#10895 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
|
@mscdex how long do you think this should bake before we land it in LTS? |
|
@MylesBorins In general I don't have an opinion on such wait times, but this is definitely a pretty straight forward, simple change, so as far as I'm concerned it could be backported at any time. |
PR-URL: #10895 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #10895 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #10895 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #10895 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Notable changes
* performance: The performance of several APIs has been improved.
- `Buffer.compare()` is up to 35% faster on average. (Brian White)
#10927
- `buffer.toJSON()` is up to 2859% faster on average. (Brian White)
#10895
- `fs.*statSync()` functions are now up to 9.3% faster on average.
(Brian White) #11522
- `os.loadavg` is up to 151% faster. (Brian White)
#11516
- `process.memoryUsage()` is up to 34% faster. (Brian White)
#11497
- `querystring.unescape()` for `Buffer`s is 15% faster on average.
(Brian White) #10837
- `querystring.stringify()` is up to 7.8% faster on average.
(Brian White) #10852
- `querystring.parse()` is up to 21% faster on average. (Brian White)
#10874
* IPC:
- Batched writes have been enabled for process IPC on platforms that
support Unix Domain Sockets. (Alexey Orlenko)
#10677
- Performance gains may be up to 40% for some workloads.
* child_process:
- `spawnSync` now returns a null `status` when child is terminated by
a signal. (cjihrig) #11288
- This fixes the behavior to act like `spawn()` does.
* http:
- Control characters are now always rejected when using
`http.request()`. (Ben Noordhuis)
#8923
- Debug messages have been added for cases when headers contain
invalid values. (Evan Lucas)
#9195
* node:
- Heap statistics now support values larger than 4GB. (Ben Noordhuis)
#10186
* timers:
- Timer callbacks now always maintain order when interacting with
domain error handling. (John Barboza)
#10522
PR-URL: #11759
Notable Changes:
* buffer:
- The performance of `.toJSON()` is now up to 2859% faster on average
(Brian White) #10895
* IPC:
- Batched writes have been enabled for process IPC on platforms that
support Unix Domain Sockets. (Alexey Orlenko)
#10677
- Performance gains may be up to 40% for some workloads.
* http:
- Control characters are now always rejected when using
`http.request()`. (Ben Noordhuis)
#8923
* node:
- Heap statistics now support values larger than 4GB. (Ben Noordhuis)
#10186
Notable Changes:
* buffer:
- The performance of `.toJSON()` is now up to 2859% faster on average
(Brian White) #10895
* IPC:
- Batched writes have been enabled for process IPC on platforms that
support Unix Domain Sockets. (Alexey Orlenko)
#10677
- Performance gains may be up to 40% for some workloads.
* http:
- Control characters are now always rejected when using
`http.request()`. (Ben Noordhuis)
#8923
* node:
- Heap statistics now support values larger than 4GB. (Ben Noordhuis)
#10186
PR-URL: #11760
Notable changes
* performance: The performance of several APIs has been improved.
- `Buffer.compare()` is up to 35% faster on average. (Brian White)
#10927
- `buffer.toJSON()` is up to 2859% faster on average. (Brian White)
#10895
- `fs.*statSync()` functions are now up to 9.3% faster on average.
(Brian White) #11522
- `os.loadavg` is up to 151% faster. (Brian White)
#11516
- `process.memoryUsage()` is up to 34% faster. (Brian White)
#11497
- `querystring.unescape()` for `Buffer`s is 15% faster on average.
(Brian White) #10837
- `querystring.stringify()` is up to 7.8% faster on average.
(Brian White) #10852
- `querystring.parse()` is up to 21% faster on average. (Brian White)
#10874
* IPC:
- Batched writes have been enabled for process IPC on platforms that
support Unix Domain Sockets. (Alexey Orlenko)
#10677
- Performance gains may be up to 40% for some workloads.
* child_process:
- `spawnSync` now returns a null `status` when child is terminated by
a signal. (cjihrig) #11288
- This fixes the behavior to act like `spawn()` does.
* http:
- Control characters are now always rejected when using
`http.request()`. (Ben Noordhuis)
#8923
- Debug messages have been added for cases when headers contain
invalid values. (Evan Lucas)
#9195
* node:
- Heap statistics now support values larger than 4GB. (Ben Noordhuis)
#10186
* timers:
- Timer callbacks now always maintain order when interacting with
domain error handling. (John Barboza)
#10522
PR-URL: #11759
|
2.5 thousand percent! |
Notable Changes:
* buffer:
- The performance of `.toJSON()` is now up to 2859% faster on average
(Brian White) nodejs/node#10895
* IPC:
- Batched writes have been enabled for process IPC on platforms that
support Unix Domain Sockets. (Alexey Orlenko)
nodejs/node#10677
- Performance gains may be up to 40% for some workloads.
* http:
- Control characters are now always rejected when using
`http.request()`. (Ben Noordhuis)
nodejs/node#8923
* node:
- Heap statistics now support values larger than 4GB. (Ben Noordhuis)
nodejs/node#10186
Signed-off-by: Ilkka Myller <ilkka.myller@nodefield.com>
Notable changes
* performance: The performance of several APIs has been improved.
- `Buffer.compare()` is up to 35% faster on average. (Brian White)
nodejs/node#10927
- `buffer.toJSON()` is up to 2859% faster on average. (Brian White)
nodejs/node#10895
- `fs.*statSync()` functions are now up to 9.3% faster on average.
(Brian White) nodejs/node#11522
- `os.loadavg` is up to 151% faster. (Brian White)
nodejs/node#11516
- `process.memoryUsage()` is up to 34% faster. (Brian White)
nodejs/node#11497
- `querystring.unescape()` for `Buffer`s is 15% faster on average.
(Brian White) nodejs/node#10837
- `querystring.stringify()` is up to 7.8% faster on average.
(Brian White) nodejs/node#10852
- `querystring.parse()` is up to 21% faster on average. (Brian White)
nodejs/node#10874
* IPC:
- Batched writes have been enabled for process IPC on platforms that
support Unix Domain Sockets. (Alexey Orlenko)
nodejs/node#10677
- Performance gains may be up to 40% for some workloads.
* child_process:
- `spawnSync` now returns a null `status` when child is terminated by
a signal. (cjihrig) nodejs/node#11288
- This fixes the behavior to act like `spawn()` does.
* http:
- Control characters are now always rejected when using
`http.request()`. (Ben Noordhuis)
nodejs/node#8923
- Debug messages have been added for cases when headers contain
invalid values. (Evan Lucas)
nodejs/node#9195
* node:
- Heap statistics now support values larger than 4GB. (Ben Noordhuis)
nodejs/node#10186
* timers:
- Timer callbacks now always maintain order when interacting with
domain error handling. (John Barboza)
nodejs/node#10522
PR-URL: nodejs/node#11759
Signed-off-by: Ilkka Myller <ilkka.myller@nodefield.com>
Notable Changes:
* buffer:
- The performance of `.toJSON()` is now up to 2859% faster on average
(Brian White) nodejs/node#10895
* IPC:
- Batched writes have been enabled for process IPC on platforms that
support Unix Domain Sockets. (Alexey Orlenko)
nodejs/node#10677
- Performance gains may be up to 40% for some workloads.
* http:
- Control characters are now always rejected when using
`http.request()`. (Ben Noordhuis)
nodejs/node#8923
* node:
- Heap statistics now support values larger than 4GB. (Ben Noordhuis)
nodejs/node#10186
Signed-off-by: Ilkka Myller <ilkka.myller@nodefield.com>
Notable changes
* performance: The performance of several APIs has been improved.
- `Buffer.compare()` is up to 35% faster on average. (Brian White)
nodejs/node#10927
- `buffer.toJSON()` is up to 2859% faster on average. (Brian White)
nodejs/node#10895
- `fs.*statSync()` functions are now up to 9.3% faster on average.
(Brian White) nodejs/node#11522
- `os.loadavg` is up to 151% faster. (Brian White)
nodejs/node#11516
- `process.memoryUsage()` is up to 34% faster. (Brian White)
nodejs/node#11497
- `querystring.unescape()` for `Buffer`s is 15% faster on average.
(Brian White) nodejs/node#10837
- `querystring.stringify()` is up to 7.8% faster on average.
(Brian White) nodejs/node#10852
- `querystring.parse()` is up to 21% faster on average. (Brian White)
nodejs/node#10874
* IPC:
- Batched writes have been enabled for process IPC on platforms that
support Unix Domain Sockets. (Alexey Orlenko)
nodejs/node#10677
- Performance gains may be up to 40% for some workloads.
* child_process:
- `spawnSync` now returns a null `status` when child is terminated by
a signal. (cjihrig) nodejs/node#11288
- This fixes the behavior to act like `spawn()` does.
* http:
- Control characters are now always rejected when using
`http.request()`. (Ben Noordhuis)
nodejs/node#8923
- Debug messages have been added for cases when headers contain
invalid values. (Evan Lucas)
nodejs/node#9195
* node:
- Heap statistics now support values larger than 4GB. (Ben Noordhuis)
nodejs/node#10186
* timers:
- Timer callbacks now always maintain order when interacting with
domain error handling. (John Barboza)
nodejs/node#10522
PR-URL: nodejs/node#11759
Signed-off-by: Ilkka Myller <ilkka.myller@nodefield.com>
Here are the results with the new, included benchmarks (I used a different
nvalue for each input length for best test result reliability while making sure they finished in a reasonable amount of time):CI: https://ci.nodejs.org/job/node-test-pull-request/5945/
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)