From 2722d8c612d1ac1901189c4155a020f9523a8fd9 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Wed, 7 Aug 2019 15:50:38 -0300 Subject: [PATCH 1/5] app boot takes 98% less time when snapd is disabled --- CHANGELOG.md | 5 +++-- fpakman/app.py | 8 -------- fpakman/core/controller.py | 21 +++++++++++++++++++-- fpakman/view/qt/thread.py | 16 +++++++++++++++- fpakman/view/qt/window.py | 15 ++++++++++++++- 5 files changed, 51 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e2e3317..9a7638d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [0.5.1] ### Improvements: -- suggestions are now retrieved asynchronously. Response time takes 45% less. -- search response time takes an average of 20% less ( reaching 35% for several results ) +- suggestions are now retrieved asynchronously taking 45% less time. +- search response takes an average of 20% less time ( reaching 35% for several results ) +- app boot takes 98% less time when snapd is disabled ### Fixes: - [flatpak dependency](https://github.com/vinifmor/fpakman/issues/36) diff --git a/fpakman/app.py b/fpakman/app.py index 89d6e8da..1535103e 100755 --- a/fpakman/app.py +++ b/fpakman/app.py @@ -21,7 +21,6 @@ from fpakman.core.snap.model import SnapApplication from fpakman.util import util from fpakman.util.cache import Cache from fpakman.util.memory import CacheCleaner -from fpakman.view.qt import dialog from fpakman.view.qt.systray import TrayIcon from fpakman.view.qt.window import ManageWindow @@ -135,18 +134,11 @@ if args.tray: manage_window=manage_window, check_interval=args.check_interval, update_notification=bool(args.update_notification)) - manage_window.tray_icon = trayIcon trayIcon.show() else: manage_window.refresh_apps() manage_window.show() -warnings = manager.list_warnings() - -if warnings: - for warning in warnings: - dialog.show_warning(title=locale_keys['warning'].capitalize(), body=warning) - CacheCleaner(caches).start() sys.exit(app.exec_()) diff --git a/fpakman/core/controller.py b/fpakman/core/controller.py index 02a3c110..dadf3f4e 100755 --- a/fpakman/core/controller.py +++ b/fpakman/core/controller.py @@ -104,6 +104,12 @@ class GenericApplicationManager(ApplicationManager): self.map = {m.get_app_type(): m for m in self.managers} self.disk_loader_factory = disk_loader_factory self._enabled_map = {} if app_args.check_packaging_once else None + self.thread_prepare = None + + def _wait_to_be_ready(self): + if self.thread_prepare: + self.thread_prepare.join() + self.thread_prepare = None def _sort(self, apps: List[Application], word: str) -> List[Application]: exact_name_matches, contains_name_matches, others = [], [], [] @@ -126,7 +132,6 @@ class GenericApplicationManager(ApplicationManager): return res def _is_enabled(self, man: ApplicationManager): - if self._enabled_map is not None: enabled = self._enabled_map.get(man.get_app_type()) @@ -145,6 +150,8 @@ class GenericApplicationManager(ApplicationManager): res['new'].extend(apps_found['new']) def search(self, word: str, disk_loader: DiskCacheLoader = None) -> Dict[str, List[Application]]: + self._wait_to_be_ready() + res = {'installed': [], 'new': []} norm_word = word.strip().lower() @@ -171,6 +178,8 @@ class GenericApplicationManager(ApplicationManager): return res def read_installed(self, disk_loader: DiskCacheLoader = None) -> List[Application]: + self._wait_to_be_ready() + installed = [] disk_loader = None @@ -262,18 +271,26 @@ class GenericApplicationManager(ApplicationManager): return man.requires_root(action, app) def refresh(self, app: Application, root_password: str) -> FpakmanProcess: + self._wait_to_be_ready() + man = self._get_manager_for(app) if man: return man.refresh(app, root_password) - def prepare(self): + def _prepare(self): if self.managers: for man in self.managers: if self._is_enabled(man): man.prepare() + def prepare(self): + self.thread_prepare = Thread(target=self._prepare) + self.thread_prepare.start() + def list_updates(self) -> List[ApplicationUpdate]: + self._wait_to_be_ready() + updates = [] if self.managers: diff --git a/fpakman/view/qt/thread.py b/fpakman/view/qt/thread.py index 3ad1fde1..401c005e 100644 --- a/fpakman/view/qt/thread.py +++ b/fpakman/view/qt/thread.py @@ -347,4 +347,18 @@ class FindSuggestions(AsyncAction): def run(self): self.signal_finished.emit(self.man.list_suggestions(limit=-1)) - \ No newline at end of file + + +class ListWarnings(QThread): + + signal_warnings = pyqtSignal(list) + + def __init__(self, man: ApplicationManager, locale_keys: dict): + super(QThread, self).__init__() + self.locale_keys = locale_keys + self.man = man + + def run(self): + warnings = self.man.list_warnings() + if warnings: + self.signal_warnings.emit(warnings) diff --git a/fpakman/view/qt/window.py b/fpakman/view/qt/window.py index a3a4a89a..946b9cb8 100755 --- a/fpakman/view/qt/window.py +++ b/fpakman/view/qt/window.py @@ -18,7 +18,7 @@ from fpakman.view.qt.history import HistoryDialog from fpakman.view.qt.info import InfoDialog from fpakman.view.qt.root import is_root, ask_root_password from fpakman.view.qt.thread import UpdateSelectedApps, RefreshApps, UninstallApp, DowngradeApp, GetAppInfo, \ - GetAppHistory, SearchApps, InstallApp, AnimateProgress, VerifyModels, RefreshApp, FindSuggestions + GetAppHistory, SearchApps, InstallApp, AnimateProgress, VerifyModels, RefreshApp, FindSuggestions, ListWarnings from fpakman.view.qt.view_model import ApplicationView DARK_ORANGE = '#FF4500' @@ -213,6 +213,19 @@ class ManageWindow(QWidget): self.dialog_about = None self.first_refresh = suggestions + self.thread_warnings = ListWarnings(man=manager, locale_keys=locale_keys) + self.thread_warnings.signal_warnings.connect(self._show_warnings) + + def _show_warnings(self, warnings: List[str]): + if warnings: + for warning in warnings: + dialog.show_warning(title=self.locale_keys['warning'].capitalize(), body=warning) + + def show(self): + super(ManageWindow, self).show() + if not self.thread_warnings.isFinished(): + self.thread_warnings.start() + def _show_about(self): if self.dialog_about is None: self.dialog_about = AboutDialog(self.locale_keys) From 49c9846868d68934843f2317994f79607fb29036 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Wed, 7 Aug 2019 15:57:58 -0300 Subject: [PATCH 2/5] improving CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a7638d4..f3e4e69e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Improvements: - suggestions are now retrieved asynchronously taking 45% less time. - search response takes an average of 20% less time ( reaching 35% for several results ) -- app boot takes 98% less time when snapd is disabled +- app boot takes 98% less time when snapd is installed, but disabled ### Fixes: - [flatpak dependency](https://github.com/vinifmor/fpakman/issues/36) From d492fcdbfb2268458b717be09acfaefb843c93bb Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Wed, 7 Aug 2019 17:56:39 -0300 Subject: [PATCH 3/5] removing gc call --- README.md | 2 +- fpakman/util/memory.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index e5edc104..11eb8d57 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ You can change some application settings via environment variables or arguments - **FPAKMAN_SNAP**: enables / disables snap usage. Use **0** (disable) or **1** (enabled, default) - **FPAKMAN_CHECK_PACKAGING_ONCE**: If the available supported packaging types should be checked ONLY once. It improves the application speed if enabled, but can generate errors if you uninstall any packaging technology while using it, and every time a supported packaging type is installed it will only be available after a restart. Use **0** (disable, default) or **1** (enable). - **FPAKMAN_TRAY**: If the tray icon and update-check daemon should be created. Use **0** (disable) or **1** (enable, default). -- **FPAKMAN_SUGGESTIONS**: If application suggestions should be displayed if no app is installed (runtimes do not count as apps). Use **0** (disable) or **1** (enable, default). +- **FPAKMAN_SUGGESTIONS**: If application suggestions should be displayed if no app are installed (runtimes do not count as apps). Use **0** (disable) or **1** (enable, default). ### How to improve the application performance - If you don't care about a specific packaging technology and don't want **fpakman** to deal with it, just disable it via the specific argument or environment variable. For instance, if I don't care diff --git a/fpakman/util/memory.py b/fpakman/util/memory.py index 35ec2659..12f65911 100644 --- a/fpakman/util/memory.py +++ b/fpakman/util/memory.py @@ -3,7 +3,6 @@ from threading import Thread from typing import List from fpakman.util.cache import Cache -import gc class CacheCleaner(Thread): @@ -20,6 +19,5 @@ class CacheCleaner(Thread): for cache in self.caches: cache.clean_expired() - gc.collect() time.sleep(self.check_interval) From b64090f2afaaf80b573aef5e1b23d6990a6ce4f1 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Wed, 7 Aug 2019 18:02:45 -0300 Subject: [PATCH 4/5] fix: README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 11eb8d57..e5edc104 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ You can change some application settings via environment variables or arguments - **FPAKMAN_SNAP**: enables / disables snap usage. Use **0** (disable) or **1** (enabled, default) - **FPAKMAN_CHECK_PACKAGING_ONCE**: If the available supported packaging types should be checked ONLY once. It improves the application speed if enabled, but can generate errors if you uninstall any packaging technology while using it, and every time a supported packaging type is installed it will only be available after a restart. Use **0** (disable, default) or **1** (enable). - **FPAKMAN_TRAY**: If the tray icon and update-check daemon should be created. Use **0** (disable) or **1** (enable, default). -- **FPAKMAN_SUGGESTIONS**: If application suggestions should be displayed if no app are installed (runtimes do not count as apps). Use **0** (disable) or **1** (enable, default). +- **FPAKMAN_SUGGESTIONS**: If application suggestions should be displayed if no app is installed (runtimes do not count as apps). Use **0** (disable) or **1** (enable, default). ### How to improve the application performance - If you don't care about a specific packaging technology and don't want **fpakman** to deal with it, just disable it via the specific argument or environment variable. For instance, if I don't care From 6313da8a7b8e980ae38ba4ded9c84090e791151a Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Wed, 7 Aug 2019 18:27:43 -0300 Subject: [PATCH 5/5] limiting 6 suggestions per packaging time --- fpakman/core/controller.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fpakman/core/controller.py b/fpakman/core/controller.py index dadf3f4e..22ce4b66 100755 --- a/fpakman/core/controller.py +++ b/fpakman/core/controller.py @@ -1,4 +1,3 @@ -import time from abc import ABC, abstractmethod from argparse import Namespace from threading import Thread @@ -326,7 +325,7 @@ class GenericApplicationManager(ApplicationManager): if self.managers: suggestions, threads = [], [] for man in self.managers: - t = Thread(target=self._fill_suggestions, args=(suggestions, man, limit)) + t = Thread(target=self._fill_suggestions, args=(suggestions, man, 6)) t.start() threads.append(t)