Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 4, 2025

Profiled the codebase and identified several performance bottlenecks causing slow queries and unnecessary allocations.

Database Indexes

Added migration 2025-11-04-043457_add_performance_indexes with 10 strategic indexes:

  • game_files(game_id), games(platform_id) - foreign key indexes
  • game_files(game_id, is_deleted) - composite index for common query pattern
  • games.is_deleted, game_files.is_deleted - filter indexes
  • game_metadata.igdb_id, platform_metadata.igdb_id - metadata lookup indexes
  • games(steam_app_id) WHERE steam_app_id IS NOT NULL - partial index

These eliminate sequential scans on queries like:

schema::game_files::table
    .filter(game_files::game_id.eq_any(&game_ids))
    .filter(game_files::is_deleted.eq(false))

Rust Optimizations

grpc-service/src/games.rs:

  • Removed redundant into_iter().collect() allocation
  • Changed clones to references (game.path.clone()ref updated_path)
  • Parallelized file deletions with join_all() instead of sequential loop

grpc-service/src/library/metadata_handlers.rs:

  • Iterate with .iter() + selective clone vs cloning entire vector upfront

React Memoization

Added React.memo to GameItem and GameImage components to prevent re-renders in virtualized lists when parent state changes but props are unchanged.

Before:

function GameItem(props: { game: Game }) { ... }

After:

const GameItem = memo(function GameItem(props: { game: Game }) { ... });
Original prompt

Identify and suggest improvements to slow or inefficient code


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@nx-cloud
Copy link

nx-cloud bot commented Nov 4, 2025

View your CI Pipeline Execution ↗ for commit 417b8ec

Command Status Duration Result
nx run-many -t cargo:lint eslint:lint ✅ Succeeded 12m 5s View ↗
nx run-many -t cargo:format prettier:format buf... ✅ Succeeded 6s View ↗
nx noop ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2025-11-05 05:03:33 UTC

Copilot AI and others added 2 commits November 4, 2025 04:33
Co-authored-by: JMBeresford <1373954+JMBeresford@users.noreply.github.com>
- Add database indexes for foreign keys and frequently queried columns
- Remove unnecessary .clone() calls in Rust code
- Replace sequential file operations with parallel execution
- Add React.memo to prevent unnecessary component re-renders
- Remove redundant into_iter().collect() operation

Co-authored-by: JMBeresford <1373954+JMBeresford@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify and suggest improvements for slow code Performance: Add database indexes and optimize hot paths Nov 4, 2025
Copilot AI requested a review from JMBeresford November 4, 2025 04:55
@JMBeresford JMBeresford requested a review from Copilot November 6, 2025 02:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR focuses on performance optimization across multiple areas of the codebase through reduction of unnecessary cloning, improved async operations, and React component memoization.

Key changes:

  • Eliminates unnecessary .clone() operations in Rust code by using references instead
  • Parallelizes file deletion operations in game and game file deletion handlers
  • Adds database indexes for improved query performance
  • Memoizes React components to prevent unnecessary re-renders

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/grpc-service/src/library/metadata_handlers.rs Optimized iteration to avoid cloning entire games collection upfront
packages/grpc-service/src/games.rs Removed unnecessary clones, parallelized disk deletions, and improved error handling
packages/db/migrations/2025-11-04-043457_add_performance_indexes/up.sql Added database indexes for foreign keys and frequently queried columns
packages/db/migrations/2025-11-04-043457_add_performance_indexes/down.sql Rollback migration for performance indexes
packages/client/gen/schemas/linux-schema.json Updated Tauri schema with new permissions and corrected spelling
packages/client-web/src/components/side-bar/game-item.tsx Wrapped component with React.memo for performance
packages/client-web/src/components/game-list.tsx Memoized GameItem and GameImage components to prevent unnecessary re-renders

Comment on lines +395 to +405
let error_msg = if path.is_dir() {
format!(
"Failed to delete game sub-directory {} from disk: {}",
file_id, why
)
} else {
format!(
"Failed to delete game file {} from disk: {}",
file_id, why
)
};
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Race condition: The path.is_dir() check at line 395 occurs after the async file system operation completes. If the path was deleted by the operation, this check will fail and produce an incorrect error message. The directory/file check should be performed before the deletion attempt (at line 388) and the result stored for use in the error message.

Copilot uses AI. Check for mistakes.
@JMBeresford JMBeresford marked this pull request as ready for review November 6, 2025 02:50
@JMBeresford JMBeresford merged commit f80b0e0 into main Nov 6, 2025
20 checks passed
JMBeresford added a commit that referenced this pull request Nov 10, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.7.43](v0.7.42...v0.7.43)
(2025-11-09)


### Features

* update emulatorJS version 4.2.1 -&gt; 4.2.3
([58de623](58de623))


### Bug Fixes

* built-in ppsspp emulation
([#433](#433))
([54c97e3](54c97e3))
* cache control header for public files
([2dad54d](2dad54d))
* catch memory access error in web emulation
([08d39c4](08d39c4))
* overlay UI tweaks
([92c4f6f](92c4f6f))


### Performance Improvements

* add database indexes and optimize hot paths
([#427](#427))
([f80b0e0](f80b0e0))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants