phoenixlauncher / phoenix

A lightweight game launcher written in SwiftUI for macOS!
https://phoenixlauncher.app
MIT License
123 stars 10 forks source link

Unnecessary games.json saving causing lag spikes #138

Closed Shock9616 closed 8 months ago

Shock9616 commented 8 months ago

Describe the bug After launching Phoenix from Xcode, I observed the [INFO]: 'games.json' updated successfully. message popping up multiple times in the console. Those messages corresponded with lag spikes which are especially noticeable while scrolling in the detail view. This only happens when I have automatic detection enabled, so I suspect that it's happening because the update function is being called every time Phoenix checks for a game, rather than only when a new game is detected.

To Reproduce Steps to reproduce the behavior:

  1. Open Phoenix (From Xcode if you want to see the logs live)
  2. Make sure that automatic game detection is on and restart if it wasn't already. (Sometimes you have to restart multiple times)
  3. Continuously scroll up and down in the detail view while watching the logs
  4. You'll notice that the lag spikes happen at the same time as the update message

Expected behavior games.json should only be updated when I actually edit a game, or if a new one is detected, not every time an already detected game is checked.

Screenshots (sorry the video was too big to upload directly) https://drive.google.com/file/d/1LJStPyNHHlnwGMjnOBhvbWvYut_YOeZo/view?usp=sharing

Logs log_2024-02-27 14:04:31.729000.log

Desktop (please complete the following information):

Additional context N/A

Shock9616 commented 8 months ago

I think part of the problem may be related to this code block in GameViewModel.swift:

func loadGames() -> [Game] {
    Task {
        var steamGameNames: Set<String> = []
        var crossoverGameNames: Set<String> = []

        if Defaults[.steamDetection] {
            steamGameNames = await detectSteamGames()
        }

        if Defaults[.crossOverDetection] {
            crossoverGameNames = await detectCrossoverGames()
        }

        await compareSteamAndCrossoverGames(steamGameNames: steamGameNames, crossoverGameNames: crossoverGameNames)
    }

    let res = loadGamesFromJSON()
    return res.games
}

The detect functions always return everything they find, so compareSteamAndCrossoverGames() has to check every detected game every time Phoenix is launched.

Shock9616 commented 8 months ago

Fixed in #139