Skip to content

Speedup opportunity in install_remove.py #92

@Bob-A-Dook

Description

@Bob-A-Dook

Hello :) I think I found an easy way to speed up opening the language pack window (in install_remove.py).

Currently, the cache object is refreshed twice when the MintLocale class is initialized. To illustrate:

class MintLocale:
    ...
    def __init__(self):
        ...
        self.cache = apt_pkg.Cache(None) #Updated
        ...
        self.build_lang_list()
        ...

    def build_lang_list(self):
        ...
        self.cache = apt_pkg.Cache(None) #Updated again

Each cache refresh is a heavy operation, taking around 0.4 seconds on my system (Mint 22.2, freshly loaded from a USB drive in live mode).

I think this can be easily improved by adding a refresh-controlling argument to build_lang_list. It could be false during initialization, but true in other cases (so that the cache stays up-to-date during future language list refreshes):

    def __init__(self):
        ...
        self.build_lang_list(refresh_cache=False)
        ...

    def build_lang_list(self, refresh_cache=True):
        ...
        if refresh_cache:
            self.cache = apt_pkg.Cache(None)

Ad-hoc benchmark

To check the speedup, I added some time measurements around the line where a MintLocale instance gets created.

from time import time

if __name__ == "__main__":
    t1 = time()
    MintLocale()
    t2 = time()
    print(t2-t1)
    Gtk.main()

Then I called the module directly (as root, so it gets access to system files):

sudo python3 /usr/lib/linuxmint/mintlocale/install_remove.py

Time before the change (2 refreshes):
1.2648556232452393

Time after the change (1 refresh):
0.7898681163787842

The effect should be noticeable to users who change language settings via the menu.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions