优化候选窗重复显示与定位更新#1869
Open
revaraver wants to merge 1 commit into
Open
Conversation
Author
|
补充几个相关 issue,主要是为了解决小狼毫输入法存在已久的输入卡顿/候选窗响应迟缓问题: 其中 #1413 里有不少用户提到 Chrome / Edge 使用一段时间后输入变慢、候选框出现有明显延迟;也有人提到把 tab 拖到新窗口后会恢复流畅。这个现象和我本地排查到的情况比较一致:卡顿更像是跟着宿主窗口状态走,而不是候选生成本身慢。 这次改动主要是减少候选窗层面的重复 |
6d7ca65 to
525349f
Compare
525349f to
392a478
Compare
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.
做了什么
这次主要减少候选窗在输入过程中的重复 UI 操作:
ShowWindow(SW_SHOWNA);ShowWindow(SW_HIDE);SetWindowPos;解决的问题
在一些长期运行的宿主程序里,比如 Chrome,用小狼毫输入时,候选窗出现会逐渐变得有明显阻尼感。
本地排查发现,慢点不在 librime 取候选结果,而主要在候选窗 UI 的显示、更新和定位路径上。宿主窗口运行时间长了以后,重复
ShowWindow/SetWindowPos的开销会被放大,导致按键后候选窗出来得慢。这个改动就是跳过明显没有必要的重复窗口状态更新,降低每次输入触发的 UI 开销。
本地对比
在本地带插桩版本中,对 Chrome 里已经变卡的窗口和修复后的新窗口做过对比,核心路径大概是:
show平均耗时:24.08ms -> 2.58mscand_update平均耗时:22.45ms -> 3.98msCandidateList.UpdateInputPosition平均耗时:25.41ms -> 11.74msUpdateComposition平均耗时:99.60ms -> 35.18ms体感上,候选窗弹出的阻尼明显下降。
说明
这不是改输入逻辑,也不改候选生成逻辑,只是减少候选窗层面的重复窗口操作。