Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

very slow start #16

Closed
legrostdg opened this issue Aug 13, 2019 · 11 comments
Closed

very slow start #16

legrostdg opened this issue Aug 13, 2019 · 11 comments
Assignees

Comments

@legrostdg
Copy link

I takes around 30s to start tartube on my laptop. Intel(R) Core(TM) i5-2540M CPU @ 2.60GHz is not the latest cpu but a small program like this should still start faster...

@axcore
Copy link
Owner

axcore commented Aug 13, 2019

I just tested Tartube (for the first time) on an Intel Celeron N4000 @1.10GHz, and the start time was 1.5 seconds. I have seen start times of about 30 seconds, but only when a lot of other things are happening.

@axcore axcore self-assigned this Aug 13, 2019
@legrostdg
Copy link
Author

My laptop was mostly idle, except firefox (but it used something like 10% of the CPU). I tried to start gimp, which was faster than tartube. When I start tartube, the CPU usage stays low, during and after the start.

@axcore
Copy link
Owner

axcore commented Aug 18, 2019

I tested v1.1.0 on a fresh install of Debian, using an ancient laptop. The startup time was 3 seconds, which is what I expected.

I'm not sure what might cause a 30-second setup time, but presumably the cause is deep within the Gtk/pygobject code somewhere. This could be tested by turning on the debug messages in the ../lib/mainapp.py file. In v1.1.0, it's line 67. You would change:

DEBUG_FUNC_FLAG = False

...to:

DEBUG_FUNC_FLAG = True

...and then run Tartube from a terminal window, so you can see the debug messages. The first message should read:

ap 87 __init__

If there is a 30-second delay before that, then I have no idea how to fix it.

@legrostdg
Copy link
Author

I tried this, the 30-second delay is still here. It occurs between ap 469 do_startup and ap 704 do_activate.

@legrostdg
Copy link
Author

(as a side note, I would probably be better to read DEBUG_FUNC_FLAG from a DEBUG environment variable)

@axcore
Copy link
Owner

axcore commented Aug 19, 2019

(as a side note, I would probably be better to read DEBUG_FUNC_FLAG from a DEBUG environment variable)

I added DEBUG_FUNC_FLAG because I was having a lot of issues with Gtk. Those issues are now solved, so I will probably remove DEBUG_FUNC_FLAG soon.

This test script is structurally the same as Tartube. Do you see a delay when you run it?

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject, GdkPixbuf


from gi.repository import Gio
import cgi
import datetime
import json
import os
import pickle
import re
import shutil
import sys
import time

try:
    import moviepy.editor
    HAVE_MOVIEPY_FLAG = True
except:
    HAVE_MOVIEPY_FLAG = False

# (Fake app ID)
__app_id__ = 'io.sourceforge.tartube_test'


class TartubeTest(Gtk.Application):


    def __init__(self, *args, **kwargs):

        super(TartubeTest, self).__init__(
            *args,
            application_id=__app_id__,
            flags=Gio.ApplicationFlags.FLAGS_NONE,
            **kwargs)


    def do_startup(self):

        """Gio.Application standard function."""

        print('Test 25: do_startup starting')
        
        GObject.threads_init()
        Gtk.Application.do_startup(self)

        # (Add a single menu action; Tartube itself has a lot of them)
        menu_action = Gio.SimpleAction.new('save_db_menu', None)
        menu_action.connect('activate', self.on_menu)
        self.add_action(menu_action)

        print('Test 37: do_startup stopped')


    def do_activate(self):

        """Gio.Application standard function."""

        print('Test 44: do_activate starting')

        self.start()

        print('Test 48: do_activate stopped')


    def do_shutdown(self):

        """Gio.Application standard function."""

        print('Test 55: do_shutdown starting')
        
        Gtk.Application.do_shutdown(self)


    def start(self):

        print('Test 62: start called')

        
    def on_menu(self, action, par):
        pass


app = TartubeTest()
app.run(sys.argv)

@legrostdg
Copy link
Author

Yes, I see the delay on this program, too. It occurs between GObject.threads_init() and Test 37: do_startup stopped

$ python3 tart.py 
Test 25: do_startup starting
tart.py:48: PyGIDeprecationWarning: Since version 3.11, calling threads_init is no longer needed. See: https://wiki.gnome.org/PyGObject/Threading
  GObject.threads_init()
Test 37: do_startup stopped
Test 44: do_activate starting
Test 62: start called
Test 48: do_activate stopped
Test 55: do_shutdown starting

@legrostdg
Copy link
Author

Gtk.Application.do_startup(self) is the culprit

@axcore
Copy link
Owner

axcore commented Aug 19, 2019

What happens when you remove the menu action?

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject, GdkPixbuf


from gi.repository import Gio
import cgi
import sys

# (Fake app ID)
__app_id__ = 'io.sourceforge.tartube_test'


class TartubeTest(Gtk.Application):


    def __init__(self, *args, **kwargs):

        super(TartubeTest, self).__init__(
            *args,
            application_id=__app_id__,
            flags=Gio.ApplicationFlags.FLAGS_NONE,
            **kwargs)


    def do_startup(self):

        """Gio.Application standard function."""

        print('Test 25: do_startup starting')
        
        GObject.threads_init()
        Gtk.Application.do_startup(self)

        print('Test 37: do_startup stopped')


    def do_activate(self):

        """Gio.Application standard function."""

        print('Test 44: do_activate starting')

        self.start()

        print('Test 48: do_activate stopped')


    def do_shutdown(self):

        """Gio.Application standard function."""

        print('Test 55: do_shutdown starting')
        
        Gtk.Application.do_shutdown(self)


    def start(self):

        print('Test 62: start called')


app = TartubeTest()
app.run(sys.argv)

@legrostdg
Copy link
Author

The same. As I said, Gtk.Application.do_startup(self) is the culprit

@legrostdg
Copy link
Author

legrostdg commented Aug 19, 2019

OK, I think I found the problem: it was related to a dbus thing. I'm starting my window manager (xmonad) with startx, and I didn't source /etc/X11/Xsession.d/.* scripts. Something with dbus was starting each time I opened tartube, implying a ~30s delay. You didn't see it because gnome/whatever was starting the dbus thing for you... So, sorry, it was a problem on my part. It's the first time in many years it happens to me, though... Maybe it will happen to someone else using a minimal window manager someday! If it does, source the /etc/X11/Xsession.d/.* scripts in your .xinitrc :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants