Skip to content

add async processor#47

Closed
steckes wants to merge 27 commits intomainfrom
next
Closed

add async processor#47
steckes wants to merge 27 commits intomainfrom
next

Conversation

@steckes
Copy link
Copy Markdown
Collaborator

@steckes steckes commented Mar 5, 2026

No description provided.

@steckes steckes requested a review from andresovela March 5, 2026 16:09
Comment thread examples/parallel_async.rs Outdated
Comment thread src/processor_async.rs Outdated
Comment thread src/processor_async.rs Outdated
Comment thread src/processor_async.rs Outdated
Comment thread src/processor_async.rs Outdated
Comment thread examples/parallel_async.rs Outdated
@steckes steckes requested a review from andresovela March 18, 2026 16:12
@steckes steckes marked this pull request as ready for review March 18, 2026 16:12
Comment thread CHANGELOG.md Outdated
Comment thread Cargo.toml Outdated
Comment thread examples/benchmark.rs
Comment thread examples/parallel_async.rs Outdated
Comment thread examples/parallel_async.rs Outdated
Comment thread examples/parallel_async.rs
Comment thread src/processor.rs Outdated
Comment thread src/processor_async.rs Outdated
Comment thread src/processor_async.rs Outdated
Comment thread examples/benchmark.rs Outdated
Comment thread examples/benchmark.rs Outdated
print!("*");
if active_threads.is_multiple_of(50) {
if spawned_sessions.is_multiple_of(50) {
print!("\n");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy suggested this:

Suggested change
print!("\n");
println!();

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why clippy does not complain here in CI and also not locally on my machine 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was shown in my editor. On the command line it seems to only be shown when using

cargo clippy --all-targets --all-features

It looks like by default tests/examples/benchmarks are not included?

We should probably change our CI settings to something like

cargo clippy --all-targets --all-features -- -D warnings

Comment thread examples/benchmark.rs Outdated
Copy link
Copy Markdown
Contributor

@Fl1tzi Fl1tzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will have a closer look tomorrow.

Comment thread src/processor_async.rs
Comment on lines +60 to +62
pub async fn initialize(&self, config: &ProcessorConfig) -> Result<(), AicError> {
let inner = Arc::clone(&self.inner);
let config = config.clone();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if cloning the ProcessingConfig is a needed step here. I would assume that we could just accept an owned ProcessorConfig and implement Copy on the ProcessorConfig.

I haven't tried but #[derive(Copy)] should just work because all the types inside the ProcessorConfig implement Copy.

Suggested change
pub async fn initialize(&self, config: &ProcessorConfig) -> Result<(), AicError> {
let inner = Arc::clone(&self.inner);
let config = config.clone();
pub async fn initialize(&self, config: ProcessorConfig) -> Result<(), AicError> {
let inner = Arc::clone(&self.inner);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct, but I like to have the function similar to the non-async processor.
And in the end copying it outside results in the same as cloning it inside.
But it is a bit more beautiful, I agree.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgeier any preference here? Leave the interface the same in both or change it here to by-value instead of by-reference?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I think I would prefer the explicit clone() and passing it by reference.

The ProcessorConfig is very small, so implicit copying might be fine for now, but if the config grows over time I think it's better to make cloning explicit.

And another thing: I'm not sure if that's happening in reality, but if we have a mutable ProcessorConfig, we might inadvertently make copies of it and then make changes to different instances, leading to confusion ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#51 suggests a way to pass the config by reference without copying (but with using unsafe).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As another data point, there's currently an open PR at cpal which suggests adding a DuplexStreamConfig which is Copy:

https://github.com/RustAudio/cpal/pull/1096/changes#diff-0a18ac1c64e2f0e86fe34809aef79ded16e15570385203969fb67e00dd8940cfR30-R36

Here is a comment regarding by value vs. by reference: RustAudio/cpal#1096 (review).

I think my argument would be the same, and I would advise against Copy.

@steckes steckes requested review from Fl1tzi and mgeier March 25, 2026 09:05
Comment thread examples/parallel_async.rs Outdated
Co-authored-by: Matthias Geier <Matthias.Geier@gmail.com>
Comment on lines +23 to +24
let model_path = Model::download(MODEL, "target")?;
let model = Model::from_file(&model_path)?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ideally the model downloading and loading should also be async as in a full async setup, you would need to spawn a blocking task here again.

/// Downloads a model file compatible with the provided model version.
///
/// The function fetches the model manifest, checks whether the requested model
/// exists in a version compatible with the given `model_version`, and downloads
/// the model file into the provided directory.
pub fn download<P: AsRef<Path>>(

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Model<'static>, AicError> {

Comment thread examples/parallel_async.rs Outdated
steckes and others added 2 commits March 25, 2026 11:55
Co-authored-by: Matthias Geier <Matthias.Geier@gmail.com>
@steckes steckes closed this Apr 28, 2026
@steckes steckes deleted the next branch April 28, 2026 12:14
@steckes steckes restored the next branch April 28, 2026 12:16
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.

4 participants