| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
Why not do new Array() and copy the items like the previous changes?
Sorry, something went wrong.
There was a problem hiding this comment.
I thought it might look a little messy since there would need to be a couple - 1s since the first item is being sliced off, but I agree it would be better to make it more similar to the other instances.
Sorry, something went wrong.
intuitively, asking the system to make extra copies does not seem to be the sort of programming that results in such speedup. of course the v8 compiler performs code transforms on our behalf as well as other robust forms of alchemy. I heard the arrow functions are an improvement on regular bind() latency, you mentioned doing: net.connect({port: 80, host: 'google.com'}, () => {});can you point me to the benchmark code, I would like to check it out? |
Sorry, something went wrong.
|
@reqshark I'll admit that benchmark is a little sketchy. At first I tried making the benchmark asynchronous where I would use the callback to close the connection and then signal that the benchmark test was complete, but that caused a bunch of errors related to opening too many connections in a short amount of time. What I ended up doing is placing a return statement inside the net/tls.connect function to return before actually opening a connection and then just running that code that I provided. It's not an accurate benchmark. It's mainly just to show that there is some performance improvement. |
Sorry, something went wrong.
|
@woollybogger You are targeting the master branch, which already has v8 4.7. Perhaps using those would be better/faster than copying arguments? |
Sorry, something went wrong.
|
is this something we want to backport? If so using rest parameters would make that more difficult |
Sorry, something went wrong.
|
@thealphanerd Is there a reason not to use rest parameters in master for the sake of backporting to other branches? I don't think so. If rest parameters are good enough, those should be used in master. If older branches need to be fixed, those should use arguments copying approach, imo. |
Sorry, something went wrong.
|
Rest parameters should turn this: Console.prototype.assert = function(expression) {
if (!expression) {
var argsLength = arguments.length || 1;
var arr = new Array(argsLength - 1);
for (var i = 1; i < argsLength; i++) {
arr[i - 1] = arguments[i];
}
require('assert').ok(false, util.format.apply(this, arr));
}
}into this: Console.prototype.assert = function(expression, ...arr) {
if (!expression) {
require('assert').ok(false, util.format.apply(this, arr));
}
} |
Sorry, something went wrong.
|
I thought rest parameters were still slow in v8? |
Sorry, something went wrong.
|
@mscdex In a single micro-benchmark, rest parameters are indeed about 2% slower than copying arguments with Node.js v5.3.0 (v8 4.6). I have not tried various cases, though. But they were not shipped by default then, and I did not check master branch (v8 4.7) yet. |
Sorry, something went wrong.
|
@mscdex Tested master branch, v8 4.7, and a few different cases (no arguments, several arguments, various types). It appears that you are correct and that rest parameters are indeed slow atm. @woollybogger Disregard my previous comments about rest parameters for now, perhaps those will be good to use in some future v8 version. |
Sorry, something went wrong.
There was a problem hiding this comment.
While you're at it, I suggest just optimizing as much as possible:
Sorry, something went wrong.
There was a problem hiding this comment.
I thought traversing/setting arrays forwards was now faster than going backwards (see #3976)?
Sorry, something went wrong.
There was a problem hiding this comment.
I'm not sure about backwards vs. forwards, but generally I've seen that for loops are faster than while loops in V8. Take a look at this benchmark I just ran (I put some of my results in a comment at the bottom): https://gist.github.com/woollybogger/7364d4cf4599a1fc0ae7
Sorry, something went wrong.
There was a problem hiding this comment.
(It also just makes the statement smaller)
Sorry, something went wrong.
There was a problem hiding this comment.
The size of the statement really just depends on coding style. I could make it the same number of lines as the while loop if I changed it to this:
var argsLength = arguments.length;
var args = new Array(argsLength);
for (var i = 0; i < argsLength; i++) args[i] = arguments[i];Would that style be preferable?
Sorry, something went wrong.
There was a problem hiding this comment.
IMHO I've always found that style (putting if/loop/etc. bodies on the same line) less readable when visually scanning code, but I would suggest removing the braces for one line bodies.
Sorry, something went wrong.
There was a problem hiding this comment.
Alright, I'll remove the braces throughout the PR.
Sorry, something went wrong.
|
Marking as a watch for v4.x but we'll need to see how this ends up before landing it there. |
Sorry, something went wrong.
Sorry, something went wrong.
|
Are there 4 Windows test runs to show that at least one of them can pass? |
Sorry, something went wrong.
|
@woollybogger ... it's kind of like playing the powerball lottery, if you roll the dice and get all green, you win big! ... unfortunately there's some current wonkiness with the windows machines due to a number of issues (a bad commit that's being looked at + unrelated build machine failures). given that LTS is mostly green and the failures look unrelated, LGTM! |
Sorry, something went wrong.
|
Cool 👍 |
Sorry, something went wrong.
|
Bump. Resolved merge conflicts. |
Sorry, something went wrong.
|
I completely rewrote my changes for assert.js and updated the benchmark results. |
Sorry, something went wrong.
There was a problem hiding this comment.
minor nit: these can be const now
Sorry, something went wrong.
|
LGTM with a nit |
Sorry, something went wrong.
Instead of leaking the arguments object by passing it as an argument to a function, copy it's contents to a new array, then pass the array. This allows V8 to optimize the function that contains this code, improving performance.
Notable changes: * **governance**: The following members have been added as collaborators: - Andreas Madsen (@AndreasMadsen) - Benjamin Gruenbaum (@benjamingr) - Claudio Rodriguez (@claudiorodriguez) - Glen Keane (@thekemkid) - Jeremy Whitlock (@whitlockjc) - Matt Loring (@matthewloring) - Phillip Johnsen (@phillipj) * **lib**: copy arguments object instead of leaking it (Nathan Woltman) #4361 * **src**: allow combination of -i and -e cli flags (Rich Trott) #5655 * **zlib**: add support for concatenated members (Kári Tristan Helgason) #5120 PR-URL: #5702
Notable changes: * **contextify**: Fixed a memory consumption issue related to heavy use of `vm.createContext` and `vm.runInNewContext`. (Ali Ijaz Sheikh) #5392 * **governance**: The following members have been added as collaborators: - Andreas Madsen (@AndreasMadsen) - Benjamin Gruenbaum (@benjamingr) - Claudio Rodriguez (@claudiorodriguez) - Glen Keane (@thekemkid) - Jeremy Whitlock (@whitlockjc) - Matt Loring (@matthewloring) - Phillip Johnsen (@phillipj) * **lib**: copy arguments object instead of leaking it (Nathan Woltman) #4361 * **src**: allow combination of -i and -e cli flags (Rich Trott) #5655 * **v8**: backport fb4ccae from v8 upstream (Vladimir Krivosheev) #4231 - breakout events from v8 to offer better support for external debuggers * **zlib**: add support for concatenated members (Kári Tristan Helgason) #5120 PR-URL: #5702
Notable changes: * **contextify**: Fixed a memory consumption issue related to heavy use of `vm.createContext` and `vm.runInNewContext`. (Ali Ijaz Sheikh) #5392 * **governance**: The following members have been added as collaborators: - Andreas Madsen (@AndreasMadsen) - Benjamin Gruenbaum (@benjamingr) - Claudio Rodriguez (@claudiorodriguez) - Glen Keane (@thekemkid) - Jeremy Whitlock (@whitlockjc) - Matt Loring (@matthewloring) - Phillip Johnsen (@phillipj) * **lib**: copy arguments object instead of leaking it (Nathan Woltman) #4361 * **src**: allow combination of -i and -e cli flags (Rich Trott) #5655 * **v8**: backport fb4ccae from v8 upstream (Vladimir Krivosheev) #4231 - breakout events from v8 to offer better support for external debuggers * **zlib**: add support for concatenated members (Kári Tristan Helgason) #5120 PR-URL: #5702
Instead of leaking the arguments object by passing it as an argument to a function, copy it's contents to a new array, then pass the array. This allows V8 to optimize the function that contains this code, improving performance. PR-URL: #4361 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
Instead of leaking the arguments object by passing it as an argument to a function, copy it's contents to a new array, then pass the array. This allows V8 to optimize the function that contains this code, improving performance. PR-URL: #4361 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
Notable Changes
* https:
- Under certain conditions ssl sockets may have been causing a memory
leak when keepalive is enabled. This is no longer the case.
- (Alexander Penev) #5713
* lib:
- The way that we were internally passing arguments was causing a
potential leak. By copying the arguments into an array we can avoid this
- (Nathan Woltman) #4361
* repl:
- Previously if you were using the repl in strict mode the column number
would be wrong in a stack trace. This is no longer an issue.
- (Prince J Wesley) #5416
PR-URL: #5961
Notable Changes
* https:
- Under certain conditions ssl sockets may have been causing a memory
leak when keepalive is enabled. This is no longer the case.
- (Alexander Penev) #5713
* lib:
- The way that we were internally passing arguments was causing a
potential leak. By copying the arguments into an array we can avoid this
- (Nathan Woltman) #4361
* npm:
- Upgrade to v2.15.1. (Forrest L Norvell)
* repl:
- Previously if you were using the repl in strict mode the column number
would be wrong in a stack trace. This is no longer an issue.
- (Prince J Wesley) #5416
PR-URL: #5961
Notable Changes
* https:
- Under certain conditions ssl sockets may have been causing a memory
leak when keepalive is enabled. This is no longer the case.
- (Alexander Penev) #5713
* lib:
- The way that we were internally passing arguments was causing a
potential leak. By copying the arguments into an array we can avoid this
- (Nathan Woltman) #4361
* npm:
- Upgrade to v2.15.1. Fixes a security flaw in the use of authentication
tokens in HTTP requests that would allow an attacker to set up a server
that could collect tokens from users of the command-line interface.
Authentication tokens have previously been sent with every request made
by the CLI for logged-in users, regardless of the destination of the
request. This update fixes this by only including those tokens for
requests made against the registry or registries used for the current
install. (Forrest L Norvell)
* repl:
- Previously if you were using the repl in strict mode the column number
would be wrong in a stack trace. This is no longer an issue.
- (Prince J Wesley) #5416
PR-URL: #5961
Notable Changes
* https:
- Under certain conditions ssl sockets may have been causing a memory
leak when keepalive is enabled. This is no longer the case.
- (Alexander Penev) #5713
* lib:
- The way that we were internally passing arguments was causing a
potential leak. By copying the arguments into an array we can avoid this
- (Nathan Woltman) #4361
* npm:
- Upgrade to v2.15.1. Fixes a security flaw in the use of authentication
tokens in HTTP requests that would allow an attacker to set up a server
that could collect tokens from users of the command-line interface.
Authentication tokens have previously been sent with every request made
by the CLI for logged-in users, regardless of the destination of the
request. This update fixes this by only including those tokens for
requests made against the registry or registries used for the current
install. (Forrest L Norvell)
* repl:
- Previously if you were using the repl in strict mode the column number
would be wrong in a stack trace. This is no longer an issue.
- (Prince J Wesley) #5416
PR-URL: #5961
| Back | FazBrowse Home | New Git URL |
Instead of leaking the arguments object by passing it as an argument to a function, copy it's contents to a new array, then pass the array. This allows V8 to optimize the function that contains this code, improving performance.
Benchmarks
Using benchmark.js
ClientRequest.setNoDelay / ClientRequest.setSocketKeepAlive
before: 15,286,485 ops/sec
after: 20,160,118 ops/sec
~33% faster
net.connect / tls.connect
before: 315,000 ops/sec
after: 345,000 ops/sec
~10% faster
code:
assert.throws
before: 98,403 ops/sec 89,592 ops/sec
after: 145,609 ops/sec 146,464 ops/sec
code: ``` js function throws() { throw Error('error message'); } // in test: assert.throws(throws); ``` #### assert.doesNotThrow before: ~~495,686 ops/sec~~ 424,867 ops/sec after: ~~7,807,355 ops/sec~~ 14,513,552 ops/sec ~~~1475% faster~~ ~3316% faster code: ``` js function doesNotThrow() { return 1 + 3; } // in test: assert.doesNotThrow(doesNotThrow); ``` #### console.assert before: 2,498,701 ops/sec after: 4,163,156 ops/sec ~67% faster code: ``` js console.assert(true); ```