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

Handle buffers directly instead of using "bl" #2424

Merged
merged 1 commit into from Oct 25, 2016
Merged

Handle buffers directly instead of using "bl" #2424

merged 1 commit into from Oct 25, 2016

Conversation

zertosh
Copy link
Contributor

@zertosh zertosh commented Oct 16, 2016

bl does a lot, but request's needs are pretty simple. This PR removes bl in favor of operating on buffers directly. There is no change in functionality here - bl also calls Buffer.concat when slicing an all buffer BufferList.

@mikeal
Copy link
Member

mikeal commented Oct 17, 2016

If i recall, the original thinking was "maybe we can eventually just pass the bl instance to the callback" instead of doing the concatenation and underlying memcopy of the buffers.

Turns out it's just too difficult to "pretend" to be a Buffer reliably and integrate with instanceof checks and Buffer.isBuffer().

@mikeal
Copy link
Member

mikeal commented Oct 17, 2016

To be clear, I'm +1 on the premise, but I haven't had the time to code review quite yet.

@zertosh
Copy link
Contributor Author

zertosh commented Oct 17, 2016

Thank you, I appreciate the background.

For context, this is just one of many more upcoming PRs. My end goal is to improve request's load time. Right now it's taking ~90-100ms - which is not a trivial amount. There are common cases in popular projects where request is in the load path, but it's not used every time. I'm investigating other optimizations like lazy loading request's deps and lazily instantiating the various support classes.

@mikeal
Copy link
Member

mikeal commented Oct 18, 2016

I wonder why the code coverage went down, this still hit a bunch of our existing tests :(

@mscdex
Copy link
Contributor

mscdex commented Oct 21, 2016

This could be improved by keeping a running total that's passed as the second argument to Buffer.concat(). It saves time by not having Buffer.concat() loop through all of the Buffers to find the total length.

@zertosh
Copy link
Contributor Author

zertosh commented Oct 24, 2016

I've updated the PR by rebasing onto master and adding the length tracking as suggested by @mscdex

@@ -1021,22 +1022,20 @@ Request.prototype.readResponseBody = function (response) {
debug('aborted', self.uri.href)
// `buffer` is defined in the parent scope and used in a closure it exists for the life of the request.
// This can lead to leaky behavior if the user retains a reference to the request object.
buffer.destroy()
buffers = []
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nit: perhaps to be consistent with the changes down below, bufferLength = 0 should be added after this line as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

@mscdex
Copy link
Contributor

mscdex commented Oct 24, 2016

LGTM and CI is green :-)

@simov simov merged commit fae254e into request:master Oct 25, 2016
@simov
Copy link
Member

simov commented Oct 25, 2016

@zertosh 👍
@mscdex you have a pending invitation to the request team from a long time ago, let me know if you want me to send you another one 👍

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.

None yet

4 participants