Skip to content

⚡ Optimize ModelManager deletion performance - #69

Merged
winnerspiros merged 4 commits into
masterfrom
model-manager-perf-optimization-8343520517278961026
Feb 6, 2026
Merged

⚡ Optimize ModelManager deletion performance#69
winnerspiros merged 4 commits into
masterfrom
model-manager-perf-optimization-8343520517278961026

Conversation

@winnerspiros

Copy link
Copy Markdown
Owner

This PR addresses the performance issue "N+1 Database Transactions in ModelManager.Delete" by batching the delete/undelete operations into a single Realm transaction.

Changes:

  • Refactored ModelManager.Delete(List<TModel>) to use a single Realm.Write transaction for the entire batch.
  • Refactored ModelManager.Undelete(List<TModel>) to use a single Realm.Write transaction for the entire batch.
  • Introduced Delete(TModel item, Realm realm) and Undelete(TModel item, Realm realm) to perform operations within an existing transaction context.
  • Added osu.Game.Tests/Database/ModelManagerPerformanceTest.cs to verify performance improvements.

Performance:

  • Baseline: ~1477ms for deleting 1000 items.
  • Optimized: ~26ms for deleting 1000 items.
  • Improvement: ~56x faster.

PR created automatically by Jules for task 8343520517278961026 started by @winnerspiros

Wraps the iteration loop in `Delete(List<TModel>)` and `Undelete(List<TModel>)` within a single `Realm.Write` block to prevent N+1 database transactions.
Adds `Delete(TModel, Realm)` and `Undelete(TModel, Realm)` overloads to support transactional context reuse.
Adds a benchmark test `ModelManagerPerformanceTest` demonstrating a performance improvement from ~1.5s to ~26ms for deleting 1000 items.

Co-authored-by: winnerspiros <1675249+winnerspiros@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules Bot and others added 3 commits February 6, 2026 03:37
Wraps the iteration loop in `Delete(List<TModel>)` and `Undelete(List<TModel>)` within a single `Realm.Write` block to prevent N+1 database transactions.
Adds `Delete(TModel, Realm)` and `Undelete(TModel, Realm)` overloads to support transactional context reuse.
Adds a benchmark test `ModelManagerPerformanceTest` demonstrating a performance improvement from ~1.5s to ~26ms for deleting 1000 items.

Co-authored-by: winnerspiros <1675249+winnerspiros@users.noreply.github.com>
Wraps the iteration loop in `Delete(List<TModel>)` and `Undelete(List<TModel>)` within a single `Realm.Write` block to prevent N+1 database transactions.
Adds `Delete(TModel, Realm)` and `Undelete(TModel, Realm)` overloads to support transactional context reuse.
Adds a benchmark test `ModelManagerPerformanceTest` demonstrating a performance improvement from ~1.5s to ~26ms for deleting 1000 items.

Co-authored-by: winnerspiros <1675249+winnerspiros@users.noreply.github.com>
Wraps the iteration loop in `Delete(List<TModel>)` and `Undelete(List<TModel>)` within a single `Realm.Write` block to prevent N+1 database transactions.
Adds `Delete(TModel, Realm)` and `Undelete(TModel, Realm)` overloads to support transactional context reuse.
Adds a benchmark test `ModelManagerPerformanceTest` demonstrating a performance improvement from ~1.5s to ~26ms for deleting 1000 items.
Fixes flaky tests in `TestSceneSoloResultsScreen` by using `AddUntilStep` for async UI assertions.

Co-authored-by: winnerspiros <1675249+winnerspiros@users.noreply.github.com>
@winnerspiros
winnerspiros merged commit 26022f8 into master Feb 6, 2026
31 checks passed
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.

1 participant