Skip to content

预加载页面以减少动画卡顿#4779

Merged
Glavo merged 2 commits intoHMCL-dev:mainfrom
Glavo:preloading
Nov 12, 2025
Merged

预加载页面以减少动画卡顿#4779
Glavo merged 2 commits intoHMCL-dev:mainfrom
Glavo:preloading

Conversation

@Glavo
Copy link
Copy Markdown
Member

@Glavo Glavo commented Nov 12, 2025

HMCL 在初次进入一部分页面时过渡动画会异常卡顿,这主要是 JavaFX 计算页面布局导致的。

为了减少这种明显的卡顿,本 PR 实现了页面预加载。当用户鼠标进入主页的部分 Tab 中时,HMCL 会预先加载页面并计算该页面的布局,这样实际打开此页面时就能正常播放过渡动画。

考虑到预加载页面主要是为了避免过渡动画异常卡顿。如果用户关闭了动画效果,我们就不进行预加载。这样对于一些低性能设备也更友好。

例如,我在 N5105 的设备上进行测试时,预加载设置页面需要约 0.9 秒,这段时间中整个 UI 会短暂无响应。通过关闭动画效果阻止预加载即可避免这种情况发生。

Copilot AI review requested due to automatic review settings November 12, 2025 12:44
Copy link
Copy Markdown
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 implements page preloading to reduce animation stuttering when first navigating to certain pages in HMCL. The preloading occurs when the user's mouse enters specific sidebar items, but only when animations are enabled to avoid performance issues on low-end devices.

Key changes:

  • Migrated DownloadPage and LauncherSettingsPage from Lazy initialization to manual nullable initialization with explicit prepare methods
  • Added utility methods prepareNode() and prepareOnMouseEnter() to support preloading
  • Integrated mouse-enter event handlers on download and settings sidebar items to trigger preloading

Reviewed Changes

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

File Description
RootPage.java Added mouse-enter event handlers to download and settings sidebar items that trigger preloading when animations are enabled
FXUtils.java Added utility methods prepareNode() for preloading nodes and prepareOnMouseEnter() for registering one-time mouse-enter handlers
Controllers.java Converted download and settings pages from Lazy to nullable fields with explicit prepare methods; updated shutdown logic
TabControl.java Made the Tab inner class final

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

downloadPage = null;
accountListPage = null;
settingsPage = null;
terracottaPage = null;
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

Type mismatch: terracottaPage is declared as Lazy<TerracottaPage> (line 115), but here it's being assigned null. Either change the field declaration to Lazy<TerracottaPage> terracottaPage (nullable) or remove this line since Lazy instances don't need to be nulled out in shutdown.

Suggested change
terracottaPage = null;

Copilot uses AI. Check for mistakes.
@burningtnt
Copy link
Copy Markdown
Member

修复后首次进入设置界面依然会出现卡顿,原因不明。

@Glavo
Copy link
Copy Markdown
Member Author

Glavo commented Nov 12, 2025

修复后首次进入设置界面依然会出现卡顿,原因不明。

部分低性能设备上似乎还是会卡,可能是还有其他负载。不过我自己和灵车群的测试来看,对大部分用户应该还是能明显改善卡顿情况。

@Glavo
Copy link
Copy Markdown
Member Author

Glavo commented Nov 12, 2025

我合到主线试试吧。如果大部分用户的设备上还有明显卡顿,那我再试试预先将页面藏到主界面的底层会不会好点。

@Glavo Glavo merged commit ae144aa into HMCL-dev:main Nov 12, 2025
8 checks passed
@Glavo Glavo deleted the preloading branch November 12, 2025 13:21
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