Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Frozen Python Application with cx_Freeze is very slow to start

I have a fairly complex python application that uses numpy, pandas, PySide, pyqtgraph, and matplotlib, among other packages. When I bundle the application with cx_Freeze on Windows, it comes in at 349MB.

My problem is the resulting executable has a very long startup time of about 15 seconds. When I say startup time, I mean the amount of time before any code gets executed. I have a simple script that prints "Hello" to the console, and even that takes about 15 seconds to run.

Does anyone know of a solution to this problem, or any ways to debug it? Is it slow because there are so many .dll files from so many packages?

EDIT: Using a great tool called Process Montor, I have narrowed down my problem to the pytz module. On one particular load, 20 seconds were spent querying the library.zip (where cx_Freeze puts all of the compiled bytecode) for pytz zoneinfo! I recently added pandas as a dependency, and pandas uses pytz.

See this picture for a sampling of the Process Monitor output: Redacted identifying info with a blueish rectangle

like image 335
John David Reaver Avatar asked Dec 28 '13 01:12

John David Reaver


1 Answers

The solution I found is to use Process Monitor to see if cx_Freeze is loading a module for an unreasonable amount of time. Using that tool, I also found that it was taking a long time (maybe 4 seconds) to load a particular matplotlib font. I removed it and my application worked fine.

like image 116
John David Reaver Avatar answered Nov 05 '22 21:11

John David Reaver