From 29beb1b64063fdc8e7da05fad6293234765b53e4 Mon Sep 17 00:00:00 2001 From: permaloom Date: Sat, 7 Feb 2026 03:58:32 -0500 Subject: [PATCH 1/2] perf: attach game references to flowbox children Store game object references in corresponding flowbox children. Avoids iterating over every single game object, reducing each flowbox child's game object access time from O(n) to O(1). --- faugus_launcher.py | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/faugus_launcher.py b/faugus_launcher.py index ac38113..bf80bed 100644 --- a/faugus_launcher.py +++ b/faugus_launcher.py @@ -703,14 +703,11 @@ class Main(Gtk.Window): selected_children = self.flowbox.get_selected_children() selected_child = selected_children[0] - hbox = selected_child.get_child() - game_label = hbox.get_children()[1] - title = game_label.get_text() + game = selected_child.game + title = game.title self.menu_item_title.get_child().set_text(title) - game = next((j for j in self.games if j.title == title), None) - with open(games_json, "r") as f: data = json.load(f) @@ -826,8 +823,7 @@ class Main(Gtk.Window): if not selected: return - title = selected[0].get_child().get_children()[1].get_text() - game = next((g for g in self.games if g.title == title), None) + game = selected[0].game if not game: return @@ -955,15 +951,12 @@ class Main(Gtk.Window): def on_duplicate_clicked(self, widget): selected_children = self.flowbox.get_selected_children() selected_child = selected_children[0] - hbox = selected_child.get_child() - game_label = hbox.get_children()[1] - title = game_label.get_text() + game = selected_child.game + title = game.title # Display duplicate dialog duplicate_dialog = DuplicateDialog(self, title) - game = next((g for g in self.games if g.title == title), None) - while True: response = duplicate_dialog.run() @@ -1506,6 +1499,7 @@ class Main(Gtk.Window): game_label.set_no_show_all(True) self.flowbox_child.add(hbox) + self.flowbox_child.game = game self.flowbox.add(self.flowbox_child) def on_search_changed(self, entry): @@ -1694,9 +1688,8 @@ class Main(Gtk.Window): return selected_child = selected_children[0] - hbox = selected_child.get_child() - game_label = hbox.get_children()[1] - title = game_label.get_text() + game = selected_child.game + title = game.title processos = self.load_processes_from_file() self.button_locked[title] = True @@ -1712,8 +1705,6 @@ class Main(Gtk.Window): return - # Find the selected game object - game = next((j for j in self.games if j.title == title), None) if game: # Format the title for command execution game_directory = os.path.dirname(game.path) @@ -1847,11 +1838,10 @@ class Main(Gtk.Window): selected_children = self.flowbox.get_selected_children() selected_child = selected_children[0] - hbox = selected_child.get_child() - game_label = hbox.get_children()[1] - title = game_label.get_text() + game = selected_child.game + title = game.title - if game := next((j for j in self.games if j.title == title), None): + if game: processos = self.load_processes_from_file() if game.title in processos: self.game_running = True @@ -1992,11 +1982,10 @@ class Main(Gtk.Window): self.reload_playtimes() selected_children = self.flowbox.get_selected_children() selected_child = selected_children[0] - hbox = selected_child.get_child() - game_label = hbox.get_children()[1] - title = game_label.get_text() + game = selected_child.game + title = game.title - if game := next((j for j in self.games if j.title == title), None): + if game: # Display confirmation dialog confirmation_dialog = ConfirmationDialog(self, title, game.prefix, game.runner) response = confirmation_dialog.run() From 09687265be2a38fd35598ad49ccc916581acf366 Mon Sep 17 00:00:00 2001 From: permaloom Date: Sat, 7 Feb 2026 13:18:31 -0500 Subject: [PATCH 2/2] perf: optimize search by toggling flowbox child visibility Toggle visibility of flowbox children based on search text instead of rebuilding the entire flowbox on every keystroke, improving search performance. --- faugus_launcher.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/faugus_launcher.py b/faugus_launcher.py index bf80bed..a88f47b 100644 --- a/faugus_launcher.py +++ b/faugus_launcher.py @@ -1504,23 +1504,19 @@ class Main(Gtk.Window): def on_search_changed(self, entry): search_text = entry.get_text().lower() - self.filtered_games = [game for game in self.games if search_text in game.title.lower()] + first_visible = None for child in self.flowbox.get_children(): - self.flowbox.remove(child) + game = child.game + is_match = search_text in game.title.lower() - if self.filtered_games: - for game in self.filtered_games: - self.add_item_list(game) + child.set_visible(is_match) + if is_match and first_visible is None: + first_visible = child - first_child = self.flowbox.get_children()[0] - self.flowbox.select_child(first_child) - self.on_item_selected(self.flowbox, first_child) - - else: - pass - - self.flowbox.show_all() + if first_visible: + self.flowbox.select_child(first_visible) + self.on_item_selected(self.flowbox, first_visible) def on_item_selected(self, flowbox, child): if child is not None: