WebConfig icon indicating copy to clipboard operation
WebConfig copied to clipboard

Excesive RAM utilisation

Open kostuch opened this issue 5 years ago • 6 comments

Hi, I'm using your lib. Good piece of work. But I slightly modified it to reduce high RAM utilisation.

The parameters should be rather covered by 'F' macro like below:

	String params = F("["
	                  "{"
	                  "'name':'XYZ',"
	                  "'label':'some label txt',"
	                  "'type':");
	params += String(INPUTPASSWORD);
	params += F(","
	            "'default':'ABCD'"
	            "},"
	            "{"
	            "'name':'ssid',"
	            "'label':'some label txt',"
	            "'type':");
	params += String(INPUTTEXT);
	params += F(","
	            "'default':'DFLT'"
	            "},"
	            "{"
	            "'name':'pwd',"
	            "'label':'some label txt',"
	            "'type':");
	params += String(INPUTPASSWORD);
	params += F(","
	            "'default':'my secret'"
	            "},"

...and so on

Also in WebConfig.cpp all const char should be defined with PROGMEM attribute:

const char HTML_START[] PROGMEM =
    "<!DOCTYPE HTML>\n"
    "<html>\n"
    "<head>\n"

...and then read by strcpy_P(_buf, HTML_START); instead of strcpy.

All literals covered by F macro, like: if (server->hasArg(F("SAVE")) instead of if (server->hasArg("SAVE") Don't forget to #include "progmem.h"

I also moved declaration huge _buf variable from private section of header to the function body void WebConfig::handleFormRequest to make it automatic var.

Above modifications can gain about 3k precious RAM for other purposes. Just look at the ESP.getFreeHeap() value before and after such modification.

kostuch avatar Feb 06 '20 10:02 kostuch

Excellent! I also noticed after compiling that the dynamic memory available was drastically reduced by 33%! Do you have a fork which include these changes and can be downloaded?

betyar avatar Aug 02 '20 19:08 betyar

Excellent! I also noticed after compiling that the dynamic memory available was drastically reduced by 33%! Do you have a fork which include these changes and can be downloaded?

I have modified fork on local disk. Besides RAM saving just minor changes like utf-8 in html header or changed controls' alignment on generated page. I can send you for the reference if you like.

kostuch avatar Aug 03 '20 08:08 kostuch

Yes, please. Thanks a lot!

betyar avatar Aug 05 '20 20:08 betyar

I have modified fork on local disk. Besides RAM saving just minor changes like utf-8 in html header or changed controls' alignment on generated page. I can send you for the reference if you like.

Hello kostuch, I am also interested in your modifications. May I ask you if you can publish your work here, or can you upload the code somewhere (maybe to Dropbox, or something similar)? Thanks in advance, Armin

ArminPP avatar Aug 06 '20 17:08 ArminPP

Sorry for late reply. If someone want to see my version, here it is: https://github.com/kostuch/webconfig I just pasted files as they are (my project is under development) - maybe something is missing at this stage. Of course all credits are going to GerLech :)

kostuch avatar Aug 22 '20 16:08 kostuch

@kostuch, can you please PR your changes to this repo?

uzadude avatar Dec 10 '21 13:12 uzadude