From: Mike Looijmans <mike.looijmans@topic.nl>
To: openembedded-core@lists.openembedded.org
Subject: Re: [OE-core] python3: Allow to specify which pyc files to keep
Date: Fri, 11 Apr 2025 10:55:11 +0200 [thread overview]
Message-ID: <73578c4c-6107-4fac-ab34-9f065db39d81@topic.nl> (raw)
In-Reply-To: <CANNYZj8JQf8tzC2g7k__TM0B967-szdV=4gt_-tBcNjXL65mXw@mail.gmail.com>
On 10-04-2025 16:31, Alexander Kanavin via lists.openembedded.org wrote:
> On Thu, 10 Apr 2025 at 15:05, Lukas Woodtli via lists.openembedded.org
> <lw=hqv.ch@lists.openembedded.org> wrote:
>> The reason to use these features of the Python interpreter is that we develop for
>> resource restricted devices. The target device should not need to compile the Python
>> files to byte-code at runtime (which happens regardless of the optimization level).
>> We can do this work at build time. Moreover, Embedded devices usually
>> have restricted storage size. So using the optimization level 2 for pyc files is sensible.
>> Most embedded devices don't need the docstrings in the Python files (simmilar to
>> not needing the man pages). So we can get rid of them (that is what optimization
>> level 2 does, apart from disabling asserts).
> Most embedded devices also need to be robust. Lest you forget, python
> and its extensions are written in C, and asserts prevent what is
> over-generously termed 'undefined behavior', with a loud crash. Which
> is a feature some people find useful. Can you demonstrate speedups?
>
> Docstrings argument as well needs to be substantiated with numbers.
> How much space is actually being saved?
>
> Is there anything else to these optimizations? Is it documented
> anywhere? How can we know if it changes over time, with new python
> releases? I feel like this needs to be considered far more carefully
> than you have so far.
Getting a deja-vu feel here... We've used a similar approach in the past for
OpenPLi, as we had to cram the full DVB settop box GUI firmware into 32MB NAND
flash for some boxes.
The impact of the "optimization" on runtime performance was negligible, and
we're talking about 200-400 MHz MIPS CPU systems in those days.
Python's optimization level 2 is sure to break things. Quite a large software
base uses asserts and docstrings for their internal purposes. One might argue
that that is "broken", but that's not something that can be fixed from this
side...
We didn't experience any ill effects from optimization level 1, so the we just
patched the Python stuff to just always use that, regardless of the file
extension being pyc.
As for space savings, the best thing was to omit the "py" files. That results
in more than halving the space required. To accomplish that, we split the
packages and put all "py" source files into a "-src" package. So on the end
product, only the pyc files got installed and developers could optionally
install some -src packages if they wanted to hack on the box itself (the major
advantage of using Python).
M.
next prev parent reply other threads:[~2025-04-11 8:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-10 6:37 python3: Allow to specify which pyc files to keep Lukas Woodtli
2025-04-10 8:02 ` [OE-core] " Alexander Kanavin
2025-04-10 11:36 ` Lukas Woodtli
2025-04-10 11:58 ` [OE-core] " Richard Purdie
2025-04-10 12:11 ` Alexander Kanavin
2025-04-10 13:05 ` Lukas Woodtli
2025-04-10 14:31 ` [OE-core] " Alexander Kanavin
2025-04-11 8:55 ` Mike Looijmans [this message]
2025-04-17 9:19 ` Lukas Woodtli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=73578c4c-6107-4fac-ab34-9f065db39d81@topic.nl \
--to=mike.looijmans@topic.nl \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox