perf(user_dict): in-memory sorted cache for user dictionary queries [WIP] - #1196
perf(user_dict): in-memory sorted cache for user dictionary queries [WIP]#1196fxliang wants to merge 11 commits into
Conversation
|
@lotem 后面那个commit不要合呀 |
|
无事,顺手让gtp 5.6看了一下。供参考: 结论:优化方向合理,LevelDB 查询收益也很明显,但当前实现存在两个会改变实际输入行为的阻塞问题,我不建议按当前 HEAD 直接合并。维护者已经批准、GitHub 当前显示可干净合并,不过现有 benchmark 没覆盖这些语义回归。[PR #1196](#1196) 必须修复
但原来的 直接影响是缓存路径返回的普通用户词条 建议让 e->code = state->code;预测词条可以继续由
key.insert(0, new_entry_prefix);但随后记录 pending 时仍然使用未加前缀的: pu.code = code_str;
应从最终 测试缺口当前新增的 630 行主要是禁用状态的性能 benchmark,并非行为回归测试。[benchmark 结果](https://github.com/rime/librime/pull/1196/files) 显示 LevelDB 查询约提升 100~570 倍,但测试基本只检查“结果非空/数量大于零”,抓不到上述问题。 合并前至少补充缓存开关两侧的等价性测试:
其他建议
整体评价:数据结构选择和性能目标值得保留,但缓存实现必须保证它只是数据库查询路径的透明替换。当前最关键的是补齐 |
|
更新了,我先拉人试毒看看 如果内存占用太大后面可以考虑加开关 |
Replace DfsLookup (per-query LevelDB forward-scans) with a sorted in-memory array built at Load() time. CacheLookup binary-searches the sorted cache (O(log N)) instead of performing multiple DB seeks. LevelDB benchmark shows ~100-570× faster lookups with no impact on load/write latency. TextDb performance is unchanged.
…y for new_entry_prefix
…Entry User DB key format requires a trailing space before the tab separator (code + " \t" + text). When custom_code is provided directly, it may lack the trailing space, causing key mismatch with DB entries loaded via the parser (which always appends a trailing space).
Cached lookups serve entirely from the in-memory cache, but Lookup() still opened a DB accessor (Query + Jump) on every call — LevelDB iterator I/O that became a ~3x slowdown once the user DB switched to a small shared block cache and 256KB write buffer to bound memory. - Create the accessor only in the DfsLookup fallback path. - Fast-path CacheLookup exact-match/predictive loops when pending_ is empty so the per-entry pending key construction is skipped. LevelDB lookups drop from ~4.5us back to ~1.3us (pre-flatten level); cached queries now only touch LevelDB for the tick point-read.
- don't merge this commit
Pull request
Issue tracker
Fixes will automatically close the related issue
Fixes #
Feature
Describe feature of pull request
Unit test
Manual test
Code Review
Additional Info