-
Notifications
You must be signed in to change notification settings - Fork 107
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
Speed up by avoiding arguments
and apply
#55
Conversation
// This function accepts the same arguments as setImmediate, but | ||
// returns a function that requires no arguments. | ||
function partiallyApplied(handler) { | ||
var args = [].slice.call(arguments, 1); |
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.
Benchmarks before and after, please. |
} else { | ||
var task = tasksByHandle[handle]; | ||
if (task) { | ||
currentlyRunningATask = true; | ||
try { | ||
task(); | ||
run(task); |
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.
Separate function, outside of try finally
for performance.
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.
ha fun fact from testing, try/finally is not an optimization killer...in v8, it is one in firefox
Benchmarks for the same case in Node.js are here; will add some for this instance as well. |
|
Awesome. Will merge and publish some time when I'm not at work. |
|
||
function setImmediate(callback) { | ||
// Callback can either be a function or a string | ||
if (typeof callback !== 'function') |
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.
curly braces around the body please
This avoids overhead with `arguments` and `apply`.
Updated code, passes |
This pull request avoids passing
arguments
around, which is bad for performance. It also avoids unnecessaryapply
calls by optimizing for common numbers of parameters, as in Node.js.