Closed proddy closed 3 months ago
Not really a PsychicHttp thing, but seeing as there is significant String
usage, I modified this line:
To enum { SSOSIZE = 32 };
. After testing, heap allocations are basically gone from String
usage. For me the few extra stack bytes is worth it.
Thanks @Chris--A - I'll try that out. When I first wrote the first version of my app, many moons ago, it was ESP8266 based I was obsessed with memory optimization and ended up writing my own string class (and later STL classes), after reading so many articles on how 'evil' Arduino's String class was (specially for non-transient operations and data duplication ops like concat()). With ESP32 I'm using std::string with allocated buffers but as you pointed out there are still String's lurking around in other libraries.
Thanks @Chris--A - I'll try that out.
Yeah, the ESP8266 and ESP32 versions have been optimized for short strings to avoid allocations. I'm new to the ESP crowd, but have been an AVR/Arduino user for many years, and yes, I would never use String
with them and did many safer recreations myself. This is the reason that I do not want to migrate to ArduinoJson 7 either. Sure its nicer, but I would like to grow the stack where I can.
However, I'm trying to use dynamic memory as little as possible so my app can safely run long term. Got an 8MB PSRAM version coming so that will be great.
Moving this to discussions
I ran some further benchmarking tests to see why PsychicHttp was using more heap memory than my original build on AsyncWebServer.
What's important to point out here is that my specific AsyncWebServer and AsyncTCP and not the original GitHub versions but very optimized over the years. The stack for example in AsyncTcp is 8192.
I used this repo's
benchmark
folder for the testing, stripping out everything except adding multiple server.ons() like:When a URI handler is registered, I see
That would explain with my 80 URI's PsychicHttp uses 12KB more heap memory.
The PsychicHttp code is clean and I don't see any areas for further optimization, so expecting this is all in the IDF.
I'll keep this open for now and report back any further findings.