Skip to content

日本語変換の辞書探索を高速化 / Speed up Japanese dictionary prediction - #1270

Merged
KazumaProject merged 2 commits into
devfrom
codex/japanese-conversion-performance
Nov 9, 2026
Merged

KazumaProject merged 2 commits into
devfrom
codex/japanese-conversion-performance

Conversation

@KazumaProject

Copy link
Copy Markdown
Owner

日本語

変更内容

実機のスタックサンプリングでは、システム辞書の補完処理が変換セッション中の 2,313 / 6,763 サンプルに現れた。変更後は 186 / 4,083 サンプルだった。

  • 補完候補の読みを設定された長さで打ち切る。入力長が補完の対象外なら、補完用のトライ探索を省く。記号・絵文字・顔文字の完全一致候補は引き続き取得する。
  • 組み込み辞書とシステムユーザー辞書の補完は、トライの終端 ID を直接使う。両辞書を通した上位のトークンだけを保持し、順位決定後に候補表記を復元する。同点では従来の辞書順・探索順・トークン順を使う。

Pixel 6 実測

Android 17(API 37)、liteStandardDebug、同じ計測 APK と同一の同梱アセット。AOT のコンパイルモードをそろえ、同梱 N-gram 辞書を有効にして、10 文の入力途中の 124 状態を各条件で 40 周計測した。時間は IME が呼び出す変換セッションの応答時間。割り当ては ART のプロセス内割り当ての平均。

設定 p50(ms) p95(ms) 割り当て/回(KiB)
既定 3.07 → 2.81 13.72 → 5.15 321.8 → 274.7
予測なし変換 2.54 → 2.51 4.80 → 4.78 259.0 → 258.2
増分セッション+文節分割+文節情報収集 5.50 → 5.14 14.28 → 11.38 281.8 → 233.9
先読み 6 文字・候補上限 16 件 3.18 → 2.88 14.78 → 5.98 357.4 → 282.2

既定の p95 は 62.5% 短縮し、3〜6 文字の p95 は 28.81 → 5.57 ms。APK を入れ替えて既定設定を再測定した場合、全入力の p95 は 13.67 → 5.17 ms、3〜6 文字は 28.97 → 5.55 ms。計測後に GC を実行した時点のプロセス PSS は 77.14 → 77.13 MiB、再測定では 76.97 → 78.67 MiB。

検証

  • 各入力途中の候補の表記、順序、スコア、文節情報を含む変換結果が、4 条件すべてで一致した。
  • 追加・変更した単体テストと Android 17 エミュレーターの通常・フローティング IME 文節変換テストが通過。変換関連の単体テストは 310 件中 304 件通過、4 件スキップ。残り 2 件の同一の失敗は変更前の dev(be49efe4a)でも再現した。
    • PackedStandaloneUnigramDictionaryTest.standaloneMatchesOnlyWholeInputLiteralReadingNodes
    • KanaKanjiConversionSessionParityTest.asciiInputKeepsHalfWidthUppercaseAcrossQueryModes
  • 実機計測では学習データやユーザー追加辞書を使用していない。リリース版とキー入力から候補表示までの時間は未計測。

English

Changes

In a separate device stack-sampling run, system dictionary completion appeared in 2,313 of 6,763 conversion-session samples on the baseline and 186 of 4,083 after the change.

  • Stop prediction traversal at the configured reading length and skip completion traversal when the input length is ineligible. Exact matches for symbols, emoji, and emoticons still use the typed reading.
  • Use the terminal IDs from the trie to rank completions across the bundled and system-user dictionaries. Keep only the highest-ranked tokens and decode their surfaces after ranking. Preserve dictionary, traversal, and token order on ties.

Pixel 6 measurements

Android 17 (API 37), liteStandardDebug, with the same instrumentation APK and identical bundled assets. Both builds used the same AOT compiler mode and bundled N-gram dictionary. Each configuration ran 40 repetitions of the 124 prefixes from 10 phrases. Timing covers the conversion session called by the IME. Allocation is the mean ART process allocation per request.

Configuration p50 (ms) p95 (ms) Allocated per request (KiB)
Default 3.07 → 2.81 13.72 → 5.15 321.8 → 274.7
Conversion without prediction 2.54 → 2.51 4.80 → 4.78 259.0 → 258.2
Incremental session with bunsetsu and segment collection 5.50 → 5.14 14.28 → 11.38 281.8 → 233.9
6-character lookahead, 16-candidate limit 3.18 → 2.88 14.78 → 5.98 357.4 → 282.2

Default p95 fell by 62.5%. For 3–6 character prefixes, p95 was 28.81 → 5.57 ms. After swapping APKs and repeating the default measurement, overall p95 was 13.67 → 5.17 ms and 3–6 character p95 was 28.97 → 5.55 ms. Post-GC process PSS was 77.14 → 77.13 MiB and 76.97 → 78.67 MiB in the repeat.

Verification

  • Conversion results matched at every tested prefix in all four configurations, including candidate text, order, scores, and segmentation.
  • Added and updated unit tests passed, as did the Android 17 emulator bunsetsu test for normal and floating IME layouts. Of 310 converter unit tests, 304 passed and four were skipped. Both failures reproduced with identical assertions on the original dev revision (be49efe4a).
    • PackedStandaloneUnigramDictionaryTest.standaloneMatchesOnlyWholeInputLiteralReadingNodes
    • KanaKanjiConversionSessionParityTest.asciiInputKeepsHalfWidthUppercaseAcrossQueryModes
  • The device benchmark used no learned entries or user-added dictionaries. Release builds and key-to-render latency were outside the measurement scope.

@KazumaProject
KazumaProject merged commit cb802cc into dev Nov 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant