interpreters/python: Optmize Python for size#3542
Open
tmedicci wants to merge 1 commit into
Open
Conversation
This aims to reduce Python's library size. Signed-off-by: Tiago Medicci <tiago.medicci@espressif.com>
xiaoxiang781216
approved these changes
Jun 15, 2026
| ARFLAGS=" " \ | ||
| MACHDEP="$(MACHDEP)" \ | ||
| OPT="-O3" \ | ||
| OPT="-Os" \ |
Contributor
There was a problem hiding this comment.
should we set OPT to empty string and let CFLAGS at line 160 control the optimization level
Contributor
Author
There was a problem hiding this comment.
I couldn't investigate it further, but it wasn't working as expected, so I set it directly on OPT for Python's configure script.
We can set this as an issue and investigate it later.
Contributor
There was a problem hiding this comment.
@tmedicci @xiaoxiang781216 I think the optimization flags should come from NuttX building system, because it was common in the past have some optimizations which crash the final firmware for some compilers, so fixing this OPT could cause that issue on some arch. But the idea of reducing size is very good, but it could come from defconfig
linguini1
approved these changes
Jun 16, 2026
jerpelea
approved these changes
Jun 16, 2026
Contributor
|
+1 from me, out of lab ;-)
…--
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info
|
eren-terzioglu
approved these changes
Jun 16, 2026
acassis
approved these changes
Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduce general firmware size by optimizing Python-related sources.
Impact
Impact on user: Yes. Enable reducing firmware size when
CONFIG_INTERPRETERS_CPYTHONis enabled.Impact on build: Yes. Reduce firmware size by ~6% (tested on ESP32-P4)
Impact on hardware: No.
Impact on documentation: No.
Impact on security: No.
Impact on compatibility: No.
Testing
Build
esp32p4-function-ev-board:pythondefconfig before and after applying this patch.Building
Running
After flashing the device, just run
pythonon NSH to ensure that it's being properly initialized.Results
Comparison between the firmwares built before and after applying this patch:
Before
And the final firmware size:
After
And the final firmware size: