fix(desktop): reduce Settings CPU spike from redundant re-renders and forced layout#4517
Open
CVEngineer66 wants to merge 1 commit into
Open
fix(desktop): reduce Settings CPU spike from redundant re-renders and forced layout#4517CVEngineer66 wants to merge 1 commit into
CVEngineer66 wants to merge 1 commit into
Conversation
…ayout Root cause (esengine#4459): configuring custom models on Windows triggered 40% CPU usage from three compounding issues: - ModelPicker re-filtered all refs on every keystroke (no debounce) - ProviderEditor reparsed modelNames on every input change (no memo) - ModelSwitcher called getBoundingClientRect() in render path Fixes: - allRefs(s) → useMemo([s.providers]) in ModelsSection - providerAccessGroups call → useMemo([s.providers, t]) in ProvidersSection - modelNames split/trim/filter → useMemo([models]) - ModelChips extracted as standalone memo component - reload/apply/backgroundApply → useCallback - uniqueStrings O(n²) → Set-based O(n) - ModelPicker + ProviderModelDraftPicker search → 150ms debounce - ModelSwitcher getBoundingClientRect → useEffect + ResizeObserver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4459
问题
设置自定义模型时 CPU 飙到 40%、UI 卡死。主要由三个编译问题叠加导致:
.includes()过滤 +new URL()解析getBoundingClientRect()直接在渲染函数内调用改动
SettingsPanel.tsxreload/apply/backgroundApply→useCallbackallRefs(s)→useMemo([s.providers])providerAccessGroups()→useMemo([s.providers, t])modelNames解析 →useMemo([models])ModelChips独立memo组件(不随 input 输入重渲染)uniqueStringsO(n²).includes()→ Set 去重 O(n)ModelPicker/ProviderModelDraftPicker搜索 → 150ms debounceModelSwitcher.tsxgetBoundingClientRect()从渲染函数移入useEffect+ResizeObserver审阅
已通过 code review,无阻塞问题。