Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Avoid large reallocations in webserver's header response#8873

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
d-a-v wants to merge4 commits intoesp8266:master
base:master
Choose a base branch
Loading
fromd-a-v:webserverwithoutholes

Conversation

d-a-v
Copy link
Collaborator

No description provided.

@earlephilhower
Copy link
Collaborator

CI seems to be aborting (not code related) frequently right about now. Let's try to re-run later...

@d-a-vd-a-v added the alphaincluded in alpha release labelFeb 28, 2023
@@ -420,7 +420,8 @@ void ESP8266WebServerTemplate<ServerType>::stop() {
}

template <typename ServerType>
void ESP8266WebServerTemplate<ServerType>::sendHeader(String&& name, String&& value, bool first) {
template <typename S1, typename S2>
void ESP8266WebServerTemplate<ServerType>::sendHeader(S1 name, S2 value, bool first) {
Copy link
Collaborator

@mcsprmcsprFeb 28, 2023
edited
Loading

Choose a reason for hiding this comment

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

minor nit

at a glance, we have a bunch of typed pairs that generate multiple emplace_... for every sendHeader variant
I'd consider using perfect forward and a specific type we already have

using Pair = std::pair<String, String>;autofoo(Pair pair,bool condition) {if (condition) {foo(std::move(pair));    }else {bar(std::move(pair));    }}template<typename S1,typename S2>autofoo(S1&& name, S2&& value,bool condition) {foo(std::make_pair(String(std::forward<S1>(name)),String(std::forward<S2>(value)), condition);}

d-a-v reacted with thumbs up emoji
@hmueller01
Copy link
Contributor

@d-a-v I have pulled your branch and did a quick test. Looks good. Thanks for the quick fix!

What I found when more that one client is connecting to the WebServer is this:

[String] 'User-Agent ... ome/110.0.': Reallocating large String(143 -> 144 bytes)[String] 'User-Agent ... 53 Mobile ': Reallocating large String(159 -> 160 bytes)

It's surely not releated to this change and I even do not know if it comes from ESPWebServer or our code ...

for (const auto& kv: _userHeaders)
if (!_streamHeader(kv.first, kv.second))
return false;
_userHeaders.clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

When will these be cleared if streaming failed?

N.B. I got the impression the current implementation of the webserver does hold some data way longer than needed as opening a web page may sometimes free up quite a bit of memory. (maybe POST data of a previous request???)

d-a-v reacted with thumbs up emoji
@hmueller01
Copy link
Contributor

I think the same happens in theESP8266HTTPClient.cpp#addHeader ...

if (first) {            _headers = headerLine + _headers;        }else {            _headers += headerLine;        }

No one knows in advance how big_headers grows. Resulting in:

[String] 'x-ESP8266- ...  1478656': Reallocating large String(134 -> 165 bytes)[String] 'x-ESP8266- ... : 548896': Reallocating large String(165 -> 221 bytes)[String] 'x-ESP8266- ... afd6bfc5': Reallocating large String(221 -> 251 bytes)[String] 'x-ESP8266- ...  2097152': Reallocating large String(251 -> 290 bytes)[String] 'x-ESP8266- ... b29dcd3)': Reallocating large String(290 -> 315 bytes)[String] 'x-ESP8266- ...  version': Reallocating large String(315 -> 338 bytes)[String] 'x-ESP8266- ... sion: 41': Reallocating large String(338 -> 357 bytes)

@hmueller01
Copy link
Contributor

@d-a-v Is there any progress on this PR / issue#8872?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@mcsprmcsprmcspr left review comments

@TD-erTD-erTD-er left review comments

Assignees
No one assigned
Labels
alphaincluded in alpha release
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@d-a-v@earlephilhower@hmueller01@mcspr@TD-er

[8]ページ先頭

©2009-2025 Movatter.jp