Repository navigation
RustのブロッキングAPIを実装 - #702
Conversation
There was a problem hiding this comment.
ブロッキング版に切り替えるのは後で。
(Java APIも同様)
There was a problem hiding this comment.
後でこのPRと同じようにvoicevox_core.asyncioとvoicevox_core.blockingを作る。
There was a problem hiding this comment.
設計としてはtokioをfeature-gateできるようにしてある。ブロッキング版はasync版に依存しない。
Hiroshiba
left a comment
There was a problem hiding this comment.
tokioをディレクトリ名にすることに関して @qryxip さんと少し議論しました!
コアの依存先がtokioではなくなった時、このRust APIの利用者にとってはAPI名が変わることになると思います。
API名が変わるのは一般的に結構強い破壊的変更だと思うけど、依存先をtokioから変更することは、API名称変えるくらい強い破壊的変更だととらえて良さそうか考えていたのですが、非同期ランタイムを変更するのは強い変更なのでそうすべきだという結論になりまた。
以下放送内コメントの引用です。
非同期ランタイムの変更となったら、それはもう「移住」みたいな感じかと
例えば、WAFは非同期ランタイムに紐付いているかと (例えばaxumは github.com/tokio-rs/axum として開発されている)
| pub fn with_words<R>(&self, f: impl FnOnce(&IndexMap<Uuid, UserDictWord>) -> R) -> R { | ||
| self.0.with_words(f) | ||
| } |
There was a problem hiding this comment.
ふと気になったのですが、impl FnOnce(&IndexMap<Uuid, UserDictWord>などは型推論してくれない感じでしょうか?
わりとコピペコードになるので書かなくていいのからもとかちょっと思いました。
こんな感じとかできないですかね。。
| pub fn with_words<R>(&self, f: impl FnOnce(&IndexMap<Uuid, UserDictWord>) -> R) -> R { | |
| self.0.with_words(f) | |
| } | |
| pub fn with_words<R>(&self, f) { | |
| self.0.with_words<R>(f) | |
| } |
みたいな・・・。
There was a problem hiding this comment.
一言で言うと無理ですね。
ScalaやHaskellならできそうですが、それらの言語でも完全に明記することの推奨はされてたと思います。
| pub async fn use_user_dict( | ||
| &self, | ||
| user_dict: &crate::tokio::UserDict, | ||
| ) -> crate::result::Result<()> { | ||
| let inner = self.0 .0.clone(); | ||
| let words = user_dict.to_mecab_format(); | ||
| crate::task::asyncify(move || inner.use_user_dict(&words)).await | ||
| } | ||
| } |
There was a problem hiding this comment.
この辺りblockingバージョンとtokioバージョンが入り組んでいて難しいなと感じました!
ちょっとよくわかってないのですが、innerを崩せたりする・・・・・・・?
(このプルリクエストで変えてほしいというよりは、後々にそうできればいいのかな、というニュアンスです!)
There was a problem hiding this comment.
UserDictの中身のHashMapをArcを包めば崩せそうではあると思います。
ただ少々影響範囲があるので、できるだけ変更範囲を狭めたいという考えからこうしています。
Hiroshiba
left a comment
There was a problem hiding this comment.
LGTM!!!!!!!
コメントを追加してほしい点と、あと名称を変えて欲しかった点が変更されているので良さそうという判断です!
色々教えてくださってありがとうございました!!
内容
Rust APIにブロッキング版を用意し、
Synthesizerなどをvoicevox_core::blocking::{Synthesizer, …}voicevox_core::tokio::{Synthesizer, …}に分けて公開するようにします。
関連 Issue
#662
その他
以下の2つはfuture workとします。
voicevox_core.blockingとvoicevox_core.asyncioに分ける