使用文件大小和修改时间(而非文件内容)作为判断词库是否修改的依据,从而提升 rime 启动速度#627
Closed
t123yh wants to merge 1 commit into
Closed
Conversation
Contributor
|
api提供快速启动模式。接口是RimeStartMaintenance。供参考。 |
Contributor
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.
Pull request
Feature
即使在词库已经 build 完成的状态下,启动 rime 仍需耗费较长时间,尤其是在树莓派等低性能设备上。我使用 rime-ice 配置,在词库已经 build 完成的情况下,再次启动 rime-api-console 程序,并在启动时对其进行 Profile 分析,可以得到如下结果:
由图可见,最耗费时间的函数是
compute_dict_file_checksum函数。究其原因,rime engine 每次启动时,DictCompiler 会检查词库是否变化,如果词库发生变化则需重新 build 词库。目前使用的检测方法,是对词库源文件做 crc32 哈希操作,并将计算好的哈希值存入数据库。由于此方法需要完整读取词库文件内容,如果词库的体积较大 且设备的 IO 性能较差,rime 的启动就会变得非常慢。以下是在我的 Ryzen 7 5700G 台式机上,使用 Debug 模式编译的 rime-api-console 的启动速度:
可以看到,rime-api-console 使用了 5.6 秒才进入可使用的状态。当然,如果用 Release 模式,性能会有所提升,但在 checksum 上花费大量时间的事实仍然成立。
我提交的 Pull Request 将“文件是否修改”的判断方法进行了调整,改为读取“文件大小+文件修改时间”并进行哈希。这样,rime 无需读取完整的词库也可以启动。
以下是使用同样的配置,应用我的修改后,rime-api-console 的启动速度。可以看到,只花费了 0.13 秒,相比原来提升了 30 倍。
运行 Profile,也提示瓶颈不再是 checksum 的计算。
Unit test
Manual test
Code Review
Additional Info