VOICEVOX / voicevox_core

無料で使える中品質なテキスト読み上げソフトウェア、VOICEVOXのコア
https://voicevox.hiroshiba.jp/
MIT License
844 stars 114 forks source link

`VoiceModel`の実装を統合する #746

Open qryxip opened 6 months ago

qryxip commented 6 months ago

内容

現在blocking::VoiceModelzipクレート、tokio::VoiceModelasync_zipクレートで別々に実装されています。blocking::VoiceModelもasync_zipを使うようにして、実装を統一します。

Pros 良くなる点

実装がバラけているのを解消できる

Cons 悪くなる点

実現方法

async_zipはtokio無しでも動くことを利用する。Rust 1.75からtrait定義に-> impl Traitを書けることを利用して上手く抽象化を行い、blocking::VoiceModelasync_zip::basetokio::VoiceModelasync_zip::tokioで駆動するようにする(async_zip v0.0.16の場合)。

VOICEVOXのバージョン

N/A

OSの種類/ディストリ/バージョン

その他

qryxip commented 5 months ago

パフォーマンス的に本当にasync_zipに統合してよいのかどうかを知るため、とりあえずmem版(ZIPファイル全体を一度読み込んでから解凍)をベンチしてみました。やはりzipよりは僅かに遅いように見えますが、実用上は誤差になると思います。

image image

コード ```toml [package] name = "bench-async-zip" edition = "2021" publish = false [[bench]] name = "bench" harness = false [dependencies] async_zip = { version = "0.0.16", features = ["deflate"] } criterion = { version = "0.5.1", features = ["html_reports"] } futures-lite = "2.2.0" zip = "0.6.6" ``` ```rust use std::{ io::{self, Cursor}, time::Duration, }; use criterion::{criterion_group, criterion_main, Criterion}; criterion_main!(benches); criterion_group! { name = benches; config = Criterion::default() .warm_up_time(Duration::from_secs(10)) .measurement_time(Duration::from_secs(20)); targets = bench } fn bench(criterion: &mut Criterion) { criterion .bench_function("zip-v0.6.6", |bencher| bencher.iter(bench_zip)) .bench_function("async_zip-v0.0.16", |bencher| bencher.iter(bench_async_zip)); } fn bench_zip() -> impl Sized { use zip::ZipArchive; let mut zip = ZipArchive::new(Cursor::new(SAMPLE_VVM.to_owned())).unwrap(); let mut entry = zip.by_name("decode.onnx").unwrap(); let mut buf = Vec::with_capacity(entry.size() as _); io::copy(&mut entry, &mut buf).unwrap(); buf } fn bench_async_zip() -> impl Sized { futures_lite::future::block_on(async { let zip = async_zip::base::read::mem::ZipFileReader::new(SAMPLE_VVM.to_owned()) .await .unwrap(); let (idx, _) = zip .file() .entries() .iter() .enumerate() .find(|(_, e)| e.filename().as_str().unwrap() == "decode.onnx") .unwrap(); let mut rdr = zip.reader_with_entry(idx).await.unwrap(); let mut buf = Vec::with_capacity(rdr.entry().uncompressed_size() as _); rdr.read_to_end_checked(&mut buf).await.unwrap(); buf }) } static SAMPLE_VVM: &[u8] = include_bytes!("../sample.vvm"); ```
Hiroshiba commented 5 months ago

やはりzipよりは僅かに遅いように見えますが、実用上は誤差になると思います。

同感です!!