feat(converter): 複数入力セッションでConverterを共有可能にする - #353
Merged
Conversation
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.
概要
1つの
KanaKanjiConverterを複数の入力コンテキストで共有できるよう、変換状態を明示的なセッションとして切り替える API を追加します。また、未保存の学習変更がない場合は学習辞書のマージとキャッシュ破棄を省略します。
背景
azooKeyDesktop の ConverterServer では、アプリごとの入力セッションごとに
KanaKanjiConverter.withDefaultDictionary()を生成していました。この構成では辞書・モデル・Converter 単位のキャッシュが実行レーンごとに重複し、新しいアプリで入力を始めるたびに初期化コストが発生します。Converter を1インスタンスに共有しつつ、入力途中の lattice・予測キャッシュ・学習文脈などは入力セッション間で混ざらない API が必要です。
共有Converterでは、アプリ切替時の
deactivateも全入力レーンと同じ実行キューを使います。従来のcommitUpdateLearningData()は変更がない場合も既存学習辞書をマージしてキャッシュを破棄するため、新しい入力レーンのキー処理を不要な同期I/Oで待たせていました。変更内容
ConversionSessionIDとcreateSession()/removeSession(_:)を追加withSession(_:operation:)で同期処理中だけ対象セッションを有効化stopComposition()が他セッションを破棄せず、現在のセッションだけを初期化するよう変更lastDataをセッション状態へ移動save()は辞書マージを行わず、呼び出し側もメモリ辞書キャッシュを維持KanaKanjiConverter自体は引き続きスレッドセーフではありません。共有する呼び出し側で Converter アクセスを直列化する前提です。テスト
swift test --filter ConverterSessionTestsswift test --filter ConverterSessionTests -Xswiftc -strict-concurrency=completeswift test --filter LearningMemoryTests(5 tests passed)ConverterTests/testKimiAndThenDeleteが辞書[006D]の欠落により失敗しますが、同じ失敗は変更前のorigin/mainでも再現します。関連