Search code examples
pythonwindowsperformancepyinstaller

App created with PyInstaller has a slow startup


I have an application written in Python and 'compiled' with PyInstaller. It also uses PyQt for the GUI framework.

Running this application has a delay of about 10 seconds before the main window loads and is shown. As far as I can tell, this is not due to slowness in my code. Instead, I suspect this is due to the Python runtime initializing.

The problem is that this application is started with a custom laucncher / taskbar application. The user will click the button to launch the app, see nothing appear to happen, and click elsewhere on another application. When my application shows it's window, it cannot come to the foreground due to the rules for SetForegroundWindow.

I have access to the source for the PyInstaller win32 loader, the Python code, and even the launcher code.

My questions are:

  • How can I make this application start faster?

  • How can I measure the time spend i the first few seconds of the process's lifetime?

  • What is the generally accepted technique for reducing time until the first window is shown?

I'd like to avoid adding a splash screen for two reasons - one, I expect it won't help (the overhead is before Python code runs) and two, I just don't like splash screens :)

If I need to, I could probably edit the PyInstaller loader stub to create a window, but that's another route i'd rather not take.


Solution

  • I have 'compiled' a few wxPython apps using py2exe and cx_Freeze, None of them take more than 4 seconds to start.

    • Are you sure sure it's not your code ? maybe some network or some I/O resource call holding your app ?
    • Have you tried other machine than yours? Even the fastest hardware can be slow sometimes with the wrong software config, apps or OS, try it.
    • Try timing it with timeit module.

    I never used pyQT, but with wxPython the startup speed is OK, and after the first initialize if I close and open again, it's faster than the first time.