lincomatic / open_evse

Firmware for Open EVSE
GNU General Public License v3.0
114 stars 163 forks source link

Size optimization #125

Closed toofishes closed 3 years ago

toofishes commented 3 years ago

First off, thanks so much for this project! I enjoyed building my OpenEVSE hardware unit a few weeks ago and wanted to contribute back, so I've already made a few pull requests to the Wifi interface. I wanted to contribute to the firmware as well. so here is my first attempt.

I've noticed a frequent concern is memory usage, since the board is rather limited in space. I thought I'd poke around a bit and find some things that could be shrunk or eliminated to save both RAM and Flash space. Thus far, I've identified a few things, each split into an individual commit (with size stats noted in the commit message) in case any of them seem risky or incorrect. Overall, these changes save 124 bytes of Flash and 8 bytes of RAM.

Starting point (commit ad4400dc):

RAM:   [=======   ]  66.1% (used 1353 bytes from 2048 bytes)
Flash: [========= ]  90.0% (used 29502 bytes from 32768 bytes)

Ending point (this branch):

RAM:   [=======   ]  65.7% (used 1345 bytes from 2048 bytes)
Flash: [========= ]  89.7% (used 29378 bytes from 32768 bytes)
lincomatic commented 3 years ago

thanks for the PR!

lincomatic commented 3 years ago

I just realized that the reason for the weird code in RTClib.cpp was that the compiler's optimizer was optimizing out some the calls where the parameter was 0. I hope that the current version we're using is OK w/ the more logical looking code you submitted. Unfortunately, I don't remember exactly what to test for