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.
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:
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):Ad-hoc benchmark
To check the speedup, I added some time measurements around the line where a
MintLocaleinstance gets created.Then I called the module directly (as root, so it gets access to system files):
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.