Skip to content

perf(core): enable MICROPY_ROM_TEXT_COMPRESSION #4961

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

Merged
merged 3 commits into from
May 15, 2025
Merged

Conversation

romanz
Copy link
Contributor

@romanz romanz commented Apr 25, 2025

Using micropython/micropython#5861 to reduce flash usage by 2.56kB on T3T1:

PYOPT=0

Memory region         Used Size  Region Size  %age Used
(After)    FLASH:     1660176 B      1664 KB     97.43%
(Before)   FLASH:     1662736 B      1664 KB     97.58%  

PYOPT=1

Memory region         Used Size  Region Size  %age Used
(After)    FLASH:     1574672 B      1664 KB     92.41%
(Before)   FLASH:     1577232 B      1664 KB     92.56%         

@romanz romanz added core Trezor Core firmware. Runs on Trezor Model T and T2B1. micropython Python interpreter and runtime that runs Trezor firmware labels Apr 25, 2025
@romanz romanz self-assigned this Apr 25, 2025
@github-project-automation github-project-automation bot moved this to 🔎 Needs review in Firmware Apr 25, 2025
@romanz romanz moved this from 🔎 Needs review to 🏃‍♀️ In progress in Firmware Apr 25, 2025
Copy link

github-actions bot commented Apr 25, 2025

core UI changes device test click test persistence test
T2T1 Model T test(screens) main(screens) test(screens) main(screens) test(screens) main(screens)
T3B1 Safe 3 test(screens) main(screens) test(screens) main(screens) test(screens) main(screens)
T3T1 Safe 5 test(screens) main(screens) test(screens) main(screens) test(screens) main(screens)
All main(screens)

@romanz romanz added core Trezor Core firmware. Runs on Trezor Model T and T2B1. and removed core Trezor Core firmware. Runs on Trezor Model T and T2B1. labels Apr 26, 2025
@romanz romanz force-pushed the romanz/compressed-text branch 2 times, most recently from 990de36 to 2e0c5bf Compare April 26, 2025 14:38
@romanz romanz moved this from 🏃‍♀️ In progress to 🔎 Needs review in Firmware Apr 27, 2025
@romanz romanz moved this from 🔎 Needs review to 🏃‍♀️ In progress in Firmware Apr 27, 2025
@romanz romanz force-pushed the romanz/compressed-text branch from 2e0c5bf to 243d7b5 Compare April 27, 2025 07:37
@romanz
Copy link
Contributor Author

romanz commented Apr 27, 2025

Tested on T3T1:

$ pytest tests/device_tests/ -k 'not authenticate and not recovery' -m 'not sd_card'
<snip>
Apr 27 12:47:03 = 1331 passed, 161 skipped, 86 deselected, 8 xfailed, 1 warning in 7605.47s (2:06:45) =

@romanz romanz force-pushed the romanz/compressed-text branch from 243d7b5 to b7c64ca Compare April 27, 2025 19:28
@romanz romanz marked this pull request as ready for review April 28, 2025 08:26
@romanz romanz requested a review from prusnak as a code owner April 28, 2025 08:26
@romanz romanz moved this from 🏃‍♀️ In progress to 🔎 Needs review in Firmware Apr 28, 2025
@romanz romanz requested review from matejcik and removed request for prusnak April 28, 2025 08:27
@romanz
Copy link
Contributor Author

romanz commented Apr 28, 2025

Since we use -ffreestanding in SConscript.firmware, I have re-mapped strcmp to __builtin_strcmp (b7c64ca) otherwise MICROPY_ROM_TEXT_COMPRESSION compile-time optimization doesn't work.
See micropython/micropython#17196 (comment) for more details.

@romanz
Copy link
Contributor Author

romanz commented May 6, 2025

BTW, applying similar approach for untranslated strings may help us save ~6kB:

$ python vendor/micropython/py/makecompresseddata.py <(jq -r .translations[] core/translations/en.json)
#define MP_MAX_UNCOMPRESSED_TEXT_LEN (171)
MP_COMPRESSED_DATA("Confir\355t\357th\345transactio\356backu\360you\362yo\365{0\375o\346share\363walle\364addres\363recover\371Th\345Transactio\356fo\362Continu\345devic\345wan\364an\344shar\345wil\354i\363Trezo\362numbe\362contain\363passphras\345PI\316Pleas\345entere\344fe\345fro\355thi\363threshol\344registratio\356reall\371no\364dat\341wit\350accoun\364device\256protection\277wallet\256cod\345Ente\362Unknow\356\341al\354recove\362Chang\345i\356S\304b\345Cance\354Se\364car\344registere\344wip\345Chec\353D\357Grou\360Stak\345{1\375differen\364followin\347hav\345Creat\345Selec\364neede\344scrip\364Accoun\364Invali\344Yo\365multisi\347wor\344Passphras\345credentia\354ke\371Shar\345amoun\364o\356word\363Sendin\347backup\256successfull\371address\256chec\353contrac\364hash\272protection\256require\344tutoria\354Sho\367Walle\364Confirmin\347delegatio\356confir\355networ\353se\364shares\256Tur\356Wip\345card\256dow\356grou\360nee\344pat\350righ\364vali\344{0}\256{0}\277Amoun\364Backu\360Numbe\362ar\345outpu\364successfully\256Increas\345account\277sequenc\345setting\363credentials\277transaction\256Lev\371Poo\354Vot\345eac\350lef\364")
MP_MATCH_COMPRESSED("Please contact Trezor support at", "\377\234contact\227support at")
MP_MATCH_COMPRESSED("Key mismatch?", "Key mismatch?")
MP_MATCH_COMPRESSED("Address mismatch?", "Address mismatch?")
MP_MATCH_COMPRESSED("trezor.io/support", "trezor.io/support")
MP_MATCH_COMPRESSED("Wrong derivation path for selected account.", "\377Wrong derivation\352\217selected account.")
MP_MATCH_COMPRESSED("XPUB mismatch?", "XPUB mismatch?")
MP_MATCH_COMPRESSED("If receive address doesn't match, contact Trezor Support at trezor.io/support.", "\377If receive\213doesn't match, contact\227Support at trezor.io/support.")
MP_MATCH_COMPRESSED("Cancel receive", "\377\265receive")
...
MP_MATCH_COMPRESSED("Remember", "Remember")
MP_MATCH_COMPRESSED("Share", "\377\316")
MP_MATCH_COMPRESSED("Shares", "Shares")
MP_MATCH_COMPRESSED("Success", "Success")
MP_MATCH_COMPRESSED("Summary", "Summary")
MP_MATCH_COMPRESSED("Threshold", "Threshold")
MP_MATCH_COMPRESSED("Try again.", "Try again.")
MP_MATCH_COMPRESSED("Unknown", "\377\255")
MP_MATCH_COMPRESSED("Unlocked", "Unlocked")
MP_MATCH_COMPRESSED("Writable", "Writable")
MP_MATCH_COMPRESSED("Yes", "Yes")
// Total input length:      21214
// Total compressed length: 13988
// Total data length:       1128
// Predicted saving:        6098

// gzip length:             11662
// Percentage of gzip:      129.6%
// zlib length:             11655
// Percentage of zlib:      129.7%

@romanz
Copy link
Contributor Author

romanz commented May 6, 2025

Will rebase to resolve a merge conflict.

@romanz romanz changed the base branch from main to romanz/less-freestanding May 6, 2025 16:34
@romanz romanz force-pushed the romanz/compressed-text branch 2 times, most recently from 1e9377c to 841f7c8 Compare May 6, 2025 17:06
@romanz romanz requested a review from mmilata May 13, 2025 05:23
@romanz romanz force-pushed the romanz/less-freestanding branch from 80004d7 to 0891dd5 Compare May 13, 2025 10:10
@romanz romanz force-pushed the romanz/less-freestanding branch from 0891dd5 to 7308fd5 Compare May 13, 2025 12:01
@romanz romanz marked this pull request as draft May 13, 2025 14:04
Base automatically changed from romanz/less-freestanding to main May 13, 2025 17:17
@romanz romanz force-pushed the romanz/compressed-text branch from a38c333 to d26fb6a Compare May 13, 2025 17:43
@romanz romanz changed the base branch from main to romanz/fix-presize-error May 13, 2025 17:48
@romanz romanz marked this pull request as ready for review May 13, 2025 18:05
@romanz romanz requested a review from mmilata May 13, 2025 18:05
@romanz romanz force-pushed the romanz/compressed-text branch from d26fb6a to 195961c Compare May 14, 2025 04:49
@romanz romanz changed the base branch from romanz/fix-presize-error to main May 14, 2025 13:06
@romanz
Copy link
Contributor Author

romanz commented May 14, 2025

Retargeted over main to include d852931 (updating MicroPython to include trezor/micropython#25).

@romanz romanz force-pushed the romanz/compressed-text branch from 195961c to 556e29b Compare May 15, 2025 06:58
@romanz romanz merged commit 556e29b into main May 15, 2025
96 checks passed
@romanz romanz deleted the romanz/compressed-text branch May 15, 2025 07:20
@github-project-automation github-project-automation bot moved this from 🔎 Needs review to 🤝 Needs QA in Firmware May 15, 2025
@bosomt bosomt moved this from 🤝 Needs QA to ✅ Approved in Firmware May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Trezor Core firmware. Runs on Trezor Model T and T2B1. micropython Python interpreter and runtime that runs Trezor firmware
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants