Skip to content

py/makeqstrdefs.py: Gzip the qstr.i.last generated output.#19312

Draft
dpgeorge wants to merge 1 commit into
micropython:masterfrom
dpgeorge:py-makeqstrdefs-gzip-output
Draft

py/makeqstrdefs.py: Gzip the qstr.i.last generated output.#19312
dpgeorge wants to merge 1 commit into
micropython:masterfrom
dpgeorge:py-makeqstrdefs-gzip-output

Conversation

@dpgeorge
Copy link
Copy Markdown
Member

@dpgeorge dpgeorge commented Jun 5, 2026

Summary

Generated qstr.i.last files can be very, very large due to inclusion of large HAL headers. The data is very repetitive text so compressing it can significantly reduce the size of the file, and hence reduce the size of the build directory and decrease wear of the filesystem.

With a clean build from scratch, using gzip level 1 changes the build output by the following amounts:

  • stm32 PYBV10: 130M -> 48M (qstr.i.last reduced by 82M)
  • rp2 RPI_PICO: 85M -> 47M (qstr.i.last reduced by 38M)
  • esp32 ESP32_GENERIC: 304M -> 244M (qstr.i.last reduced by 60M)

This can amount to significant savings when building all boards for a port, eg saving up to 6GB building all stm32 boards.

It saves less on a rebuild because qstr.i.last only contains preprocessor output from files that changed since the previous build.

Built time is increased slightly due to the compression: about 0.5-1 second slower (out of a total 30s build time, which includes 4s generating qstr.i.last) for stm32 PYBV10, which is around 3% slower.

Using compresslevel=9 saves about 2M more but almost doubles the time taken to generate qstr.i.last (going from 4s up to 8s or more). So using compresslevel=1 is the best trade off here.

Testing

Tested building the above ports and measured output size.

CI will test the rest.

Trade-offs and Alternatives

Costs a small amount of time to compress/decompress, but using level 1 keeps this time down to a minimum.

The qstr.i.last data is no longer readable in an editor, without first decompressing it (which is pretty easy to do if you ever need to view this data).

Generative AI

Not used.

Generated `qstr.i.last` files can be very, very large due to inclusion of
large HAL headers.  The data is very repetitive text so compressing it can
significantly reduce the size of the file, and hence reduce the size of the
build directory and decrease wear of the filesystem.

With a clean build from scratch, using gzip level 1 changes the build
output by the following amounts:
- stm32 PYBV10: 130M -> 48M (`qstr.i.last` reduced by 82M)
- rp2 RPI_PICO: 85M -> 47M (`qstr.i.last` reduced by 38M)
- esp32 ESP32_GENERIC: 304M -> 244M (`qstr.i.last` reduced by 60M)

This can amount to significant savings when building all boards for a port,
eg saving up to 6GB building all stm32 boards.

It saves less on a rebuild because `qstr.i.last` only contains preprocessor
output from files that changed since the previous build.

Built time is increased slightly due to the compression: about 0.5-1 second
slower (out of a total 30s build time, which includes 4s generating
`qstr.i.last`) for stm32 PYBV10, which is around 3% slower.

Using `compresslevel=9` saves about 2M more but almost doubles the time
taken to generate `qstr.i.last` (going from 4s up to 8s or more).  So
using `compresslevel=1` is the best trade off here.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label Jun 5, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.47%. Comparing base (af38ee1) to head (78b8ead).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #19312   +/-   ##
=======================================
  Coverage   98.47%   98.47%           
=======================================
  Files         176      176           
  Lines       22845    22845           
=======================================
  Hits        22497    22497           
  Misses        348      348           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

Code size report:

Reference:  samd/mphalport: Run events at least once in mp_hal_delay_ms. [af38ee1]
Comparison: py/makeqstrdefs.py: Gzip the qstr.i.last generated output. [merge of 78b8ead]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@dpgeorge
Copy link
Copy Markdown
Member Author

dpgeorge commented Jun 5, 2026

Oh, the windows builds have a special processing step ConcatPreProcFiles which doesn't work well with this compression. Maybe that step can be generalised to work with all ports instead of using compression, because it does a very similar thing (reduces size of qstr.i.last).

@dpgeorge dpgeorge marked this pull request as draft June 5, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

py-core Relates to py/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant