Skip to content

py/makeqstrdefs.py: Filter out unneeded lines from qstr.i.last early on.#19323

Open
dpgeorge wants to merge 1 commit into
micropython:masterfrom
dpgeorge:py-makeqstrdefs-pp-filter
Open

py/makeqstrdefs.py: Filter out unneeded lines from qstr.i.last early on.#19323
dpgeorge wants to merge 1 commit into
micropython:masterfrom
dpgeorge:py-makeqstrdefs-pp-filter

Conversation

@dpgeorge

@dpgeorge dpgeorge commented Jun 9, 2026

Copy link
Copy Markdown
Member

Summary

Generated qstr.i.last files (output from the "pp" phase) can be very large due to inclusion of large HAL headers. Yet only a small amount of this data is actually needed by the "split" phase of makeqstrdefs.py.

This commit improves the situation by filtering out unneeded lines as early as possible: in the "pp" phase the C preprocessor runs, its output is parsed via a pipe connection, and only those lines that are needed are written out to the qstr.i.last file. When the "split" phase runs it then sees only the necessary lines (it does further regex filtering to get exactly the lines it needs for the given mode).

Windows already does this filtering (it does not use makeqstrdefs.py for the preprocessor phase) in its ConcatPreProcFiles function, and that was added long ago in 29c8c8a.

This change significantly reduces the output build size and improves the build speed:

  • stm32 BOARD=PYBV10: build output goes from 152M down to 32M, and build is 10% faster (29s down to 26s). Building all stm32 boards, the total build size goes from about 11GB down to about 2.5GB.

  • rp2 BOARD=RPI_PICO: build output goes from 87M down to 39M, and build is about 5% faster (23s down to 21.6s).

  • esp32 BOARD=ESP32_GENERIC: build output goes from 307M down to 230M, and build is about 6% faster (101s down to 95s).

Testing

Tested all three ports above, that the files in build/genhdr are equivalent (except of course qstr.i.last), and that PYBV10 is binary equivalent before and after this change.

Trade-offs and Alternatives

Tried using gzip in #19312, but the approach here is far better.

Now need to keep the regex's in sync, between the "pp" and "split" phases.

Generative AI

Not used.

Generated `qstr.i.last` files (output from the "pp" phase) can be very
large due to inclusion of large HAL headers.  Yet only a small amount of
this data is actually needed by the "split" phase of `makeqstrdefs.py`.

This commit improves the situation by filtering out unneeded lines as early
as possible: in the "pp" phase the C preprocessor runs, its output is
parsed via a pipe connection, and only those lines that are needed are
written out to the `qstr.i.last` file.  When the "split" phase runs it then
sees only the necessary lines (it does further regex filtering to get
exactly the lines it needs for the given mode).

Windows already does this filtering (it does not use `makeqstrdefs.py` for
the preprocessor phase) in its `ConcatPreProcFiles` function, and that
was added long ago in 29c8c8a.

This change significantly reduces the output build size and improves the
build speed:

- stm32 BOARD=PYBV10: build output goes from 152M down to 32M, and build is
  10% faster (29s down to 26s).  Building all stm32 boards, the total build
  size goes from about 11GB down to about 2.5GB.

- rp2 BOARD=RPI_PICO: build output goes from 87M down to 39M, and build is
  about 5% faster (23s down to 21.6s).

- esp32 BOARD=ESP32_GENERIC: build output goes from 307M down to 230M, and
  build is about 6% faster (101s down to 95s).

Tested all three ports above, that the files in build/genhdr are equivalent
(except of course `qstr.i.last`), and that PYBV10 is binary equivalent
before and after this change.

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

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #19323   +/-   ##
=======================================
  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

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Code size report:

Reference:  samd/mphalport: Run events at least once in mp_hal_delay_ms. [af38ee1]
Comparison: py/makeqstrdefs.py: Filter out unneeded lines from qstr.i.last early on. [merge of 947efd3]
  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

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