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

Performance: reserve body to avoid frequent reallocations and copies #1781

Closed
wants to merge 1 commit into from

Conversation

ArnaudBienner
Copy link
Contributor

When doing some profiling on a client application doing a lot of downloads, I realized my application spent ~13% of its time doing std::string::append (compiled with gcc and -03, even more when compiling in debug mode with -O1: ~30%).

I realized this could be improved by reserving the output buffer (res.body) since we know the output size if Content-Length header is present.

@ArnaudBienner
Copy link
Contributor Author

I've implemented an alternative in #1782.

@yhirose
Copy link
Owner

yhirose commented Feb 24, 2024

@ArnaudBienner I don't think std::string::append gets called after your code, because the rest of code after the line 6069 in Server::write_response_core is only for writing res.body or data from a content provider to a network socket. So res.body won't be changed. Could you confirm that your code really works? Thanks!

@ArnaudBienner
Copy link
Contributor Author

Sorry: I made that work on an older version of the library, and it looks like the patch wasn't correctly imported with git apply.

I made a new PR by copying the code by hand, to the correct location this time: #1788.

I'll close this PR.

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.

2 participants