Skip to content
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: micro-optimize url.resolve() #184

Merged
merged 2 commits into from
Dec 20, 2014

Conversation

bnoordhuis
Copy link
Member

Replace the call to Array#splice() with a faster open-coded version
that creates less garbage.

Add a new benchmark to prove it. With the change applied, it scores
about 5% higher and that is nothing to sneeze at.

R=@chrisdickinson

@aredridel
Copy link
Contributor

Wow, neat!

for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
list[i] = list[k];
list.pop();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice trick to know about. Especially since splice is quite slow. :o

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indenting is a bit off here.

@bnoordhuis
Copy link
Member Author

Wait until you see the numbers for EventEmitter#removeListener(). :-)

@bnoordhuis
Copy link
Member Author

@chrisdickinson Fixed the indentation and renamed the function to spliceOne(). PTAL.

@algesten
Copy link

👍

@chrisdickinson
Copy link
Contributor

LGTM

Rename the url.parse() benchmark from url.js to url-parse.js.
A follow-up commit is going to add another one for url.resolve().

PR-URL: nodejs#184
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Replace the call to Array#splice() with a faster open-coded version
that creates less garbage.

Add a new benchmark to prove it.  With the change applied, it scores
about 5% higher and that is nothing to sneeze at.

PR-URL: nodejs#184
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
@bnoordhuis bnoordhuis merged commit aff56cd into nodejs:v0.12 Dec 20, 2014
@bnoordhuis bnoordhuis deleted the micro-optimize-url-resolve branch December 20, 2014 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants