Perf: Optimized list loading of FontComboBox#6254
Conversation
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces asynchronous loading of system fonts in FontComboBox to prevent UI freezing. However, the current implementation still blocks the UI thread during class loading because Font.getFamilies() is called in static initializers. Additionally, there are concurrency issues, such as the potential to spawn multiple loading threads on multiple clicks, a lack of thread visibility for the loaded flag, and the background thread not being set as a daemon thread. The review comments suggest moving the font retrieval to the background thread, marking loaded as volatile, checking if a thread is already running before starting a new one, and setting the thread as a daemon.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request modifies FontComboBox.java to load font families asynchronously in a background thread, preventing UI blocking. It initially loads the first 10 fonts and then fetches the remaining fonts in batches of 30 using a daemon thread. The review feedback highlights critical thread-safety and performance issues: declaring allFonts and headFonts as static fields introduces race conditions across multiple instances, calling itemsProperty().unbind() on a background thread violates JavaFX threading rules, and using stream filtering to find remaining fonts is inefficient compared to using subList.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request modifies FontComboBox to load system fonts asynchronously in batches, preventing UI thread blocking when opening the font dropdown. The review feedback highlights opportunities to improve thread safety by copying the font list on the UI thread before passing it to the background thread, and to prevent a potential memory leak by clearing the loadingThread reference and updating the loaded state on the JavaFX Application Thread once loading completes.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
我考虑之后重构一下,做成基于 LineButton 的实现,让用户在新的对话框中选择字体。 |
优化
FontComboBox列表加载缘由
更改
实况
测试环境字体总数:335
更改前
1.mp4
更改后
2.mp4