-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
lib: Prevent leaking arguments in several places. #1752
Conversation
/cc @Fishrock123 |
The total list of issues found:
I'm not sure if fixing most of those matters, but at least some should be fixed imo. |
e917608
to
bdf3e6f
Compare
If I get time, I'll run IRHydra against my patch and see what comes out. That would be the best first step, to compare the actual compiled result. |
throw new TypeError('Arguments to path.join must be strings'); | ||
} | ||
return p; | ||
var paths = []; |
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.
Perhaps specifying the length up front, var paths = new Array(arguments.length);
and assigning at the index would be faster?
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.
@brendanashworth Done.
bdf3e6f
to
dd51d5b
Compare
A while back, we had support for macro expansion in our native modules. If this is proving to be a generally viable speedup, it would be nice to put it in macro form so that it's easy to rip out again if V8 changes things. |
var al = arguments.length - 1; | ||
var arr = new Array(al > 0 ? al : 0); | ||
while (al-- > 0) arr[al] = arguments[al + 1]; | ||
|
||
require('assert').ok(false, util.format.apply(this, arr)); |
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.
There's another obvious performance optimization here: cache the result of require('assert')
. :-)
A comment and a question:
|
2: Iirc last time we checked |
If you're referring to the OSR issue, I think I only saw that with |
this jsperf shows that |
@Fishrock123, @bnoordhuis Compound assignment deoptimizes |
dd51d5b
to
8bf79b4
Compare
@bnoordhuis Done:
|
@brendanashworth Ow. That jsperf shows that |
We should probably move to preferring const (where correct/possible) in all new patches then. |
LGTM |
Should I patch other places from #1752 (comment) ? |
@ChALkeR yes please :) |
The |
I'd be a lot more comfortable with this if it were reintroduced as a macro. It'd be a lot easier to document / spread knowledge about its use, as well as to back out of it if perf characteristics change. |
@chrisdickinson This is a temporary solution anyways. Related: https://code.google.com/p/v8/issues/detail?id=2159 A macro (and documenting it) seems like a bit undue for a temporary hack. |
@ChALkeR In my experience rest params are already almost on par with using |
@trevnorris «On par with See https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments. |
@ChALkeR I'm aware of all that. Was just stating that rest params being well optimized isn't far off. |
@trevnorris Yes. And that's why I don't see an advantage in hacking this with something more complex, as macro (and documenting it), as @chrisdickinson proposed here: #1752 (comment) |
@ChALkeR @trevnorris ... what's the status on this? |
@jasnell I need to re-apply this (some places mentioned in the above list were already fixed by other patches), and then re-test to see if there is any actual improvement with the current v8 version in master. |
Closing, obsolete. See #4361, also current |
This prevents leaking arguments in several places.
Not yet final, I will probably update this with more patches, waiting for comments.
Currently the three fixed places are
util.format
(called for example byconsole.log
),console.assert
, andpath.win32.join
.In
path.win32.join
this PR changes the stack of theTypeError('Arguments to path.join must be strings')
, removing the topat f (path.js:190:13)
andat Object.filter (native)
so now it is similar to the stack inpath.posix.join
.util.format
results:util.format('abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc1234567890')
(16700000 ⇒ 32900000 ops/second).util.format({a:2,b:10,c:10},20,'d')
(50000 ⇒ 54000 ops/second).util.format('Hello %s %s',20,'d')
(580000 ⇒ 800000 ops/second).console.assert
results:console.assert(true, 'text')
(2550000 ⇒ 3230000 ops/second).console.assert(true)
( 3000000 ⇒ 3700000 ops/second).path.win32.join
results:path.join('a','b','c')
(400000 ⇒ 598000 ops/second).See #1749 (comment), https://gist.github.com/Fishrock123/98c35a0c745cb59d7496 and https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments