Skip to content

[Settings] Speed up page navigation; fix Advanced Paste double-load#47909

Draft
niels9001 wants to merge 1 commit into
mainfrom
niels9001/settings-page-load-perf
Draft

[Settings] Speed up page navigation; fix Advanced Paste double-load#47909
niels9001 wants to merge 1 commit into
mainfrom
niels9001/settings-page-load-perf

Conversation

@niels9001
Copy link
Copy Markdown
Collaborator

Summary

Settings pages — Advanced Paste in particular — felt slow on navigation and visibly "loaded twice". This PR addresses three coupled root causes.

What was happening

  1. No frame caching. <Frame x:Name="shellFrame" /> had no caching and no page set NavigationCacheMode, so every nav click rebuilt a fresh Page instance, ViewModel, file watcher, and IPC subscriptions, and re-ran InitializeComponent on a 577-line / 41 KB XAML tree.
  2. Cards entrance animation replayed on every nav. SettingsCardsAnimations bundled an EntranceThemeTransition (FromVerticalOffset=50) that fired every time a page came up.
  3. Advanced Paste did duplicate dialog setup in Loaded. UpdatePasteAIUIVisibility() and UpdateFoundryLocalUIAsync() ran on every nav even though both only touch controls inside the hidden provider-configuration dialog. The Add/Edit handlers already call them right before ShowAsync(). The Loaded work produced a visible second reflow (the "double load") and, when the saved provider was Foundry Local, kicked off a process probe on every nav.

Changes

  • NavigablePage.cs — Set NavigationCacheMode = NavigationCacheMode.Enabled in the base ctor. All pages inheriting NavigablePage (most settings pages) are now cached. Frame's default CacheSize=10 is enough to hold every top-level module. OnNavigatedTo and Loaded still fire on each visit, so existing per-nav logic (element-targeting animation, hotkey conflict refresh) keeps working.
  • App.xaml — Removed EntranceThemeTransition from SettingsCardsAnimations. Kept RepositionThemeTransition so SettingsExpander still animates expand/collapse smoothly.
  • AdvancedPastePage.xaml.cs
    • Removed the duplicate UpdatePasteAIUIVisibility() + await UpdateFoundryLocalUIAsync() calls from the Loaded handler.
    • Added _isPasteAIProviderDialogOpen tracking, set when the dialog opens and cleared in its Closed handler.
    • RefreshEnabledState() now only runs the dialog-state updates while the dialog is actually open, so an IPC general-settings broadcast can no longer trigger a duplicate Foundry probe in the background.

Result

  • Re-navigating between settings pages is essentially instant on the second visit.
  • The visible "second load" reflow on Advanced Paste is gone.
  • No more Foundry Local process probe on every Advanced Paste nav for users who picked it as their provider.
  • Expander expand/collapse animations are unchanged.

Out of scope (potential follow-ups)

  • Move heavy Advanced Paste ViewModel ctor work (InitializePasteAIProviderState, MigrateLegacyAIEnablement, PropertyChanged wiring) off the UI thread.
  • Debounce the settings file watcher to suppress events that immediately follow our own writes.
  • App-scope cache for Foundry Local availability so even the first dialog open is faster.
  • Audit other heavy pages (FancyZones, MouseUtils, KeyboardManager, ZoomIt) for similar deferred-work opportunities — they all already benefit automatically from the new nav cache.

Validation

  • Manual: nav between Dashboard ↔ Advanced Paste ↔ FancyZones repeatedly.
  • IRefreshablePage path still triggers VM refresh on external general-settings updates.
  • Note: a full local build was not completed in this environment due to a pre-existing C++ spdlog/fmt header incompatibility unrelated to these changes. The C# changes are isolated and were reviewed manually.

- Enable NavigationCacheMode.Enabled in NavigablePage so pages inheriting it are kept warm by the Frame; re-navigation no longer rebuilds the XAML tree, ViewModel, file watchers and IPC handlers each time.

- Drop EntranceThemeTransition from SettingsCardsAnimations. It replayed on every nav and produced a visible cards-in animation on top of an already slow construction. RepositionThemeTransition is preserved so SettingsExpander expand/collapse stays smooth.

- AdvancedPastePage: stop calling UpdatePasteAIUIVisibility() and UpdateFoundryLocalUIAsync() in the Loaded handler. They only affect controls inside the (hidden) provider configuration dialog, and the Add/Edit handlers already call them right before ShowAsync. Removing the duplicate work eliminates the visible second reflow (the 'double load') and avoids an unnecessary Foundry Local process probe on every nav.

- Guard RefreshEnabledState so dialog-only updates only run while the provider configuration dialog is actually open, preventing duplicate work on IPC general-settings broadcasts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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