-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Firmware size savings #3236
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Firmware size savings #3236
Conversation
c1f97b5
to
930000e
Compare
Many of these strings are already in the qstr pool. Do you want to switch these to |
This is a slight trade-off with code size, in places where a "_varg" mp_raise variant is now used. The net savings on trinket_m0 is just 32 bytes. It also means that the translation will include the original English text, and cannot be translated. These are usually names of Python types such as int, set, or dict or special values such as "inf" or "Nan".
This saves a very small amount of flash, 8 bytes on trinket_m0
63bfaec
to
d3fb6ff
Compare
I've heavily revised this PR and now it contains a couple of substantial size savers. |
This removes runtime allocations of the cstring version of the qstring. It is not a size improvement
This saves nearly 200 bytes. Curiously, it also saves RAM.
The missing second "const" made these mutable arrays pointing to const string data.
This function computes the remainder of a value `x` modulo pi/2, to high precision. It does this by dividing the flotaing point values into several ranges by magnitude, and applies successively slower but more accurate algorithms. The last two steps, one covering values up to around 2^7 * pi/2 (called "medium size") and a final one covering all possible float values, require big tables. By eliminating the "medium size" case, a table and some code are removed from the binary. This makes some cases take longer, but saves hundreds of bytes. It does _NOT_ affect the result, only the speed. ``` [desktop python] >>> sum(math.sin(2.**i) for i in range(21)) 1.4206898748939305 [trinket m0, before change to ef_rem_pio2.c] >>> sum(math.sin(2.**i) for i in range(21)) 1.42069 [trinket m0, after change to ef_rem_pio2.c] >>> sum(math.sin(2.**i) for i in range(21)) 1.42069 ```
This array was of 32-bit values, but the entries were only ever in the 0-255 range. Convert to uint8_t. Testing performed: The result of the sum-of-sin was unchanged >>> import math; sum(math.sin(2.**i) for i in range(21)) 1.42069
d3fb6ff
to
6669ced
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay! Excellent analysis, particularly on the math routines.
Saves 12 bytes code on trinket m0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
I ended up finding a range of firmware size (flash utilization) improvements. One item is a performance trade-off, and one item is a feature removal for the most constrainted boards.
A small amount of RAM is also saved.
Baseline: c394af4 (origin/main) Merge pull request #3241 from jepler/translation-percent-space-fixes
Binary: trinket_m0 en_US
Flash free: +1404 bytes
RAM free: +76 bytes
Total translation strings: -17