[Python-Dev] Embedded Python startup is slow

bruce bushby bruce.bushby at gmail.com
Thu Mar 24 16:58:20 CET 2011


My main concern was that a freshly compiled Python attempts to open 168
non-existent files before starting.

I understand that an interpreted language is probably not the best choice
for an embedded device (although it's very nice for prototyping) , Python
really should know what exists after it's just been compiled....ie before
any corrupting modules or other nonsense has been added.

It appears it is hard coded to open these files regardless of any
"configure" options.

On my desktop pc, when I run the most simple "Hello World" .... 78% of the
overall execution time is spent opening files....most of which don't exist.

Some form of "cache" would help the startup time on the "second go" .....
but arguably just a "band aid" covering a deeper problem.


Bruce





On Thu, Mar 24, 2011 at 3:23 PM, Thomas Heller <theller at ctypes.org> wrote:

> Am 24.03.2011 12:18, schrieb "Martin v. Löwis":
>
>  1. Is there anything I can do at compile time to tell Python these files
>>> don't exist and avoid trying to open them?
>>>
>>
>> If you disable dynamic loading of extension modules, the number of stat
>> calls will go down significantly.
>>
>>  2. Is it possible to make python first try and open the ".pyc" and only
>>> then look for ".py" ?
>>>
>>
>> If you then further reduce sys.path, and zip up the standard library
>> .pyc files, you get further reductions.
>>
>
> On my embedded ARM system (400MHz ARM926EJ-S, linux 2.6.38) Python
> starts up even slower when the standard library is in a zip-file.
> The effect is worse when the zip-file is compressed, but the slow-down
> is still there if the zip-file is not compressed.
>
> Thomas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20110324/a801a40b/attachment.html>


More information about the Python-Dev mailing list