lincomatic / open_evse

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

Code size optimization: smaller types in readAmmeter #128

Closed toofishes closed 3 years ago

toofishes commented 3 years ago

By avoiding as much 32-bit math and preferring 8-bit and 16-bit math, we can generate smaller code, even if more local variables are needed.

Before:

RAM:   [=======   ]  65.7% (used 1345 bytes from 2048 bytes)
Flash: [========= ]  89.7% (used 29378 bytes from 32768 bytes)

After:

RAM:   [=======   ]  65.7% (used 1345 bytes from 2048 bytes)
Flash: [========= ]  89.5% (used 29314 bytes from 32768 bytes)

This change saves 64 bytes of flash.

Note: I'm relatively confident I implemented identical logic between the old and new code, but I have no testbed hardware to verify this.