Skip to content

Conversation

@adamkaplan
Copy link
Collaborator

Based on this comment that I agree with from @Macarse #253 (review)

The request reading is very inefficient by reading 1 byte at a time. In theory the OS might be buffering much more data because it knows how inefficient that is, but we should still see significant speed improvements by reading large amounts of data at once. This is due to the large amount of buffer allocation thrash.

The new approach is to read up to 1KB of request data in one shot. Now, a response with 4,500 bytes would see 4x 1024B reads, and then a 404 byte read to finish up. Before this PR, it would be 4,500 individual reads.

I also changed the unit test mock Socket to use actual OS sockets. This way we can test the read read flows!

@adamkaplan adamkaplan requested a review from Vkt0r January 23, 2019 21:31
Copy link
Member

@Vkt0r Vkt0r left a comment

Choose a reason for hiding this comment

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

LGTM! Definitely is a really good improvement in the reading speed.

@Vkt0r Vkt0r merged commit 56a7356 into stable Jan 28, 2019
@adamkaplan adamkaplan deleted the faster-request-reading branch January 28, 2019 15:37
@Macarse
Copy link

Macarse commented Jan 28, 2019

Can we get a release with this change? :)

tomieq pushed a commit to tomieq/swifterfork that referenced this pull request Apr 1, 2021
Faster reading of request body and headers
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.

4 participants