Repository navigation
perf: 按鍵熱路徑的段級重排快取與更正索引,行為不變 - #51
Merged
Merged
Conversation
Signed-off-by: Oliver Yu <[email protected]>
Signed-off-by: Oliver Yu <[email protected]>
Signed-off-by: Oliver Yu <[email protected]>
Signed-off-by: Oliver Yu <[email protected]>
評分源實作 MassVersion 才啟用;未實作者維持每次重建。 Signed-off-by: Oliver Yu <[email protected]>
只影響記憶體內的快取鍵;浮點數由 %.9g 改最短往返表示。 Signed-off-by: Oliver Yu <[email protected]>
Signed-off-by: Oliver Yu <[email protected]>
Contributor
|
已合併,會隨 0.2.9 發布。合併後我們補了四處,用 0.2.8 的資料包和內附神經模型重跑,快照和改動前逐行相同。
另外,第 1 點修好後快取會真的命中,評分器暫時失敗時就和原本不同:原本 |
Contributor
|
已隨 0.2.9 發布。正式套件上用 350 句(10,343 鍵)加 120 句含游標移動、刪除與開候選的操作,0.2.8 與 0.2.9 交替跑兩輪,送出的字逐字相同;每鍵 p99 從約 45–52 ms 降到 37–42 ms。 |
pohsun4work
pushed a commit
to pohsun4work/0c-ime
that referenced
this pull request
Nov 6, 2026
…keystrokes Sync ime 0.2.9 (PR 0c-biggo#51 is already here, so its ime port is not repeated; ime's review follow-ups on it are included): "My vocabulary" exports to a text file and imports on another computer, a new optional shift-symbol-halfwidth setting types half-width punctuation with Shift (0c-biggo#50), mixed input composes a medial or final typed one key late by position (20u4 電, 9j4 外, u1,6 別), and the segment rerank cache, the correctionIndex and the kept massScale (capped at 16,384) nearly halve the per-key engine time with the neural reranker; the golden transcript test becomes a caches on/off comparison per seed. Windows links the C runtime statically for x64 too, a changed previous version no longer blocks installing, the keyboard compartment is opened on activation for IMM32 programs, IMM32 text boxes get English autocomplete and Ctrl shortcuts in the right order, Caps Lock lower case works without a caret, and the status summary lists recent programs from tsf.log. Dictionary and models are unchanged.
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.
問題與結果
長句持續輸入時,每按一鍵都會對整句重跑神經重排的 N-best 與評分,個人更正查詢也逐 span 組字串比對。句子越長越慢,快取命中後剩下的成本仍然不小。
這個 PR 只改成本,不改行為:同樣的按鍵序列,產生的 Snapshot 與 main 逐字節相同。沒有使用者可見的變化,個人資料格式也沒變。
perf(decode)offer 去重offer去重時拼好的文字直接傳給新增的extendText,不再拼第二次perf(session)重排段rerankMemo:段內輸入(讀音、段內顯示、前文、個人資料版本等)都沒變就重放上次的 winner 與提示,不重跑 N-best。評分器暫時失敗不記錄perf(personal)更正比對correctionIndex,逐音節核對,不再逐 span 組鍵perf(session)補全與語音提示sugKey)沒變就沿用上次的補全建議與語音提示perf(decode)massScalemassScale跨搜尋保留,經選配介面MassVersion(Model實作為(Gen, Store.Time))失效perf(session)strconvtest(session)golden驗證
沒有下載
assets/,以下全部使用 repo 內的 toy 詞庫。與 main 的差分:golden 是在分支上產生的,不能自證等價,所以另外對 merge-base(
1338efa)做差分。把隨機操作測試的主體複製到 base 的 worktree,兩邊跑同一組 seed、輸出逐行cmp:TestRerankGoldenTranscript直接通過。go test ./core/session -run TestRerankGolden -count=2通過;-update重寫後git diff為空。審查中找到並已修正的問題:對照 main 檢查快取輸入時,發現兩處會與 main 不同。隨機操作測試沒有抓到,所以是靠讀程式碼確認的:
refreshSelection在pathSig不變時換掉s.path,sugKey沒收 path,補全建議會沿用舊路徑的結果。現在sugKey收整條 path。contextLeft、ContextRunes、SeparateContinuation,也沒收shownPath詞的位置與旗標。現在都收了。prepareMass比較評分源身分時,遇到不可比較的型別會 panic。現在遇到就不保留。新增的
TestRerankSuggestionFresh檢查沿用的補全建議等於重算結果;它在修正前的程式碼上跑 1500 個 seed 也沒失敗,所以第一點目前沒有能重現的測試。全套檢查(Linux,tip 為最後一個 commit):
python3 scripts/check_public_tree.py:通過go vet ./...:通過go test -count=1 ./...:通過make -C platforms/linux-fcitx5 test:通過make test-upgrade:34 個測試通過make test-release:通過(輸出有一行fatal: Needed a single revision,來自test_source_release.py,該套件通過)Benchmark:base 與分支在同一台機器上交替跑 3 輪取中位數(AMD EPYC 9575F,toy 詞庫):
沒有基準變慢。否決路徑(OverturnsUserLongSegment)如預期不變。
benchmark 原始輸出(3 輪)
指令:
尚未驗證:
assets/:以上數字與差分都用 toy 詞庫,真實詞庫下的加速比與等價性沒測。make test-upgrade與make test-release只在 Linux 跑。相容性與證據
MassVersion是選配介面,第三方Adaptive實作不必修改;沒實作的來源維持每次重建。%.9g改最短往返表示)只影響記憶體內的快取鍵,沒有寫入檔案或經過 IPC。rerankMemo、sugPrev:reset()(提交、取消)清空;輸入摘要含Gen、Store.Time,個人資料變動就不命中。massScale:(Gen, Store.Time)或評分源改變、HasAdaptation()轉為 false 時清空。rerankCache、d.cacheTopM、topPrefixed、correctionIndex/habitIndex、Store.Time的每小時量化、extendShown、neuralKeeps/overturnsUser、weakPrefix。Rerank.NeutralExpand、NeutralBases與 Scorer 身分;這些只在開 session 時設定,main 的rerankCache鍵也沒收。Model.Store卻不遞增Gen,快取會過期;production 都在第一次解碼前換好。fmt.Fprintf,沒有改成 strconv。之後可以做(這個 PR 不含):
decode.extend的 backpointer、Pythonprepare()的 O(c·n²)、IPC 雙寫、個人片語view.Exact的線性掃描、Engine.Do持鎖跨同步評分。建議先用真實資產量過,再決定要不要繼續。