Skip to content

Populate the skin gallery on demand to reduce startup time#2902

Merged
rwmcintosh merged 1 commit into
V13from
2901-defer-skin-gallery
Jul 4, 2026
Merged

Populate the skin gallery on demand to reduce startup time#2902
rwmcintosh merged 1 commit into
V13from
2901-defer-skin-gallery

Conversation

@rwmcintosh

@rwmcintosh rwmcintosh commented Jul 3, 2026

Copy link
Copy Markdown
Member

Fixes #2901

Part of a broader effort to cut PK-Sim / MoBi startup time (Open-Systems-Pharmacology/PK-Sim#1472) — ~5 s combined across the fixes below. The ribbon skin gallery was built entirely at startup (one command + two skin-styled bitmaps per skin, ~50 skins). It is now populated on first use — when the drop-down is opened or its ribbon page is selected. Startup skin restore is unaffected. MoBi gets the same win via the shared OSPSuite.UI code.

Approximate startup savings across the investigation:

Fix Repository Saving
ValueOriginRepository re-mapping bug (guard Start()) PK-Sim ~1.0 s
Background (parallel) repository warm-up PK-Sim ~1.0 s
Journal editor built on demand PK-Sim ~1.9 s
Skin gallery populated on demand (this PR) OSPSuite.Core ~1.4 s

So, when you click the Utilities tab, there is a small delay because that's when the gallery is built. We could move this gallery if it feels weird, the other tabs are instant.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The skin gallery mapper now populates gallery items lazily on first use—triggered by dropdown initialization or ribbon page selection—instead of eagerly during MapFrom. A pageContains helper checks selected pages, and the redundant event subscription in createSkinGallery was removed.

Changes

Lazy skin gallery population

Layer / File(s) Summary
Lazy population wiring
src/OSPSuite.UI/Mappers/SkinManagerToSkinGalleryMapper.cs
Introduces a populateGallery local function invoked via InitDropDownGallery and SelectedPageChanged (using a new pageContains helper and System.Linq) to build skin gallery items on demand, replacing eager population in MapFrom and removing the now-redundant subscription in createSkinGallery.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Ribbon
  participant SkinManagerToSkinGalleryMapper
  participant SkinManager

  User->>Ribbon: Open skins dropdown / select ribbon page
  Ribbon->>SkinManagerToSkinGalleryMapper: InitDropDownGallery / SelectedPageChanged
  SkinManagerToSkinGalleryMapper->>SkinManagerToSkinGalleryMapper: pageContains(skins gallery item)
  SkinManagerToSkinGalleryMapper->>SkinManagerToSkinGalleryMapper: populateGallery()
  SkinManagerToSkinGalleryMapper->>SkinManager: All()
  SkinManagerToSkinGalleryMapper->>SkinManagerToSkinGalleryMapper: resolve ActivateSkinCommand per skin, add gallery items
Loading

Poem

A rabbit hops, no time to waste,
Startup swift, no skins to baste,
Gallery sleeps till clicked awake,
Then paints its coats for goodness' sake,
Hop hop hooray, less time to bake! 🐰🎨

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The mapper now populates the gallery on first use via dropdown open and ribbon page selection, matching #2901.
Out of Scope Changes check ✅ Passed The changes are limited to the skin gallery lazy-loading behavior and supporting LINQ/event wiring.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: deferring skin gallery population to improve startup time.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2901-defer-skin-gallery

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/OSPSuite.UI/Mappers/SkinManagerToSkinGalleryMapper.cs (1)

34-67: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Guard condition works but relies on an implicit invariant.

Using rgbiSkins.Gallery.Groups[0].Items.Count > 0 as the "already populated" check is a bit indirect — a future change to addSkinToGallery/createSkinGallery that alters group indexing or clears items could silently break the guard and cause a re-population/duplication bug. Consider an explicit boolean flag captured in the closure for clarity and robustness.

♻️ Suggested clarity improvement
+         var isPopulated = false;
+
          void populateGallery()
          {
-            if (rgbiSkins.Gallery.Groups[0].Items.Count > 0)
-               return;
+            if (isPopulated)
+               return;
+
+            isPopulated = true;
 
             foreach (var skin in skinManager.All())

The rest of the wiring (dual triggers via InitDropDownGallery and SelectedPageChanged, pageContains scoping) looks correct and matches the PR's lazy-population goal.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/OSPSuite.UI/Mappers/SkinManagerToSkinGalleryMapper.cs` around lines 34 -
67, The lazy-population guard in the SkinManagerToSkinGalleryMapper logic relies
on rgbiSkins.Gallery.Groups[0].Items.Count, which is an implicit invariant and
can break if addSkinToGallery or createSkinGallery changes group/item structure.
Replace that check inside populateGallery() with an explicit closure-captured
boolean flag that tracks whether the gallery has already been populated, and set
it after the first successful population so both InitDropDownGallery and
SelectedPageChanged keep working without duplicate entries.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/OSPSuite.UI/Mappers/SkinManagerToSkinGalleryMapper.cs`:
- Around line 34-67: The lazy-population guard in the
SkinManagerToSkinGalleryMapper logic relies on
rgbiSkins.Gallery.Groups[0].Items.Count, which is an implicit invariant and can
break if addSkinToGallery or createSkinGallery changes group/item structure.
Replace that check inside populateGallery() with an explicit closure-captured
boolean flag that tracks whether the gallery has already been populated, and set
it after the first successful population so both InitDropDownGallery and
SelectedPageChanged keep working without duplicate entries.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 116c6b69-2a19-459b-be89-f6842bcb251b

📥 Commits

Reviewing files that changed from the base of the PR and between 2efa3c3 and 6790b0a.

📒 Files selected for processing (1)
  • src/OSPSuite.UI/Mappers/SkinManagerToSkinGalleryMapper.cs

@rwmcintosh rwmcintosh requested review from Yuri05 and msevestre July 3, 2026 22:18
@rwmcintosh rwmcintosh self-assigned this Jul 3, 2026
@Yuri05

Yuri05 commented Jul 4, 2026

Copy link
Copy Markdown
Member

nice!

@rwmcintosh rwmcintosh merged commit 24f0c43 into V13 Jul 4, 2026
2 checks passed
@rwmcintosh rwmcintosh deleted the 2901-defer-skin-gallery branch July 4, 2026 16:34
@msevestre

Copy link
Copy Markdown
Member

cool

Journal editor built on demand

what about remving journla editor :)

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.

3 participants