Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip_duration takes ~600ms to run #338

Closed
FredrikNoren opened this issue Nov 4, 2020 · 10 comments
Closed

skip_duration takes ~600ms to run #338

FredrikNoren opened this issue Nov 4, 2020 · 10 comments

Comments

@FredrikNoren
Copy link

Hi,

I'm playing around with rodio for a project, and I noticed I got freeze lags when I was playing some sounds. After some digging it turned out that the culprit was calling skip_duration on a source. It seems like it gets worse the longer the skip is. This is in debug mode, but skipping 3secs takes 600ms to run for me which seems a bit extreme. This is on OSX.

To repro, just take the first example in the docs and add skip_duration to it, like this:

let file = File::open("sound.ogg").unwrap();
let source = rodio::Decoder::new(BufReader::new(file)).unwrap();

let now = Instant::now();
stream_handle.play_raw(source.convert_samples().skip_duration(Duration::from_secs_f32(3.))).unwrap();
println!("{}", now.elapsed().as_secs_f32() * 1000.);

Results on my machine (in debug):

  • Without skip: 0.04ms
  • With skip: 658ms
@est31
Copy link
Member

est31 commented Nov 4, 2020

It's runnning the entire decoder in the background, and is faster than realtime at that. If you want to decode something more quickly, you can enable optimizations for your dependencies through cargo profile dependencies. Sadly there is no cargo option yet for the dependencies to enable them themselves.

This should greatly improve stuff for you:

[profile.dev.overrides."lewton"]
opt-level = 3

@est31 est31 closed this as completed Nov 4, 2020
@FredrikNoren
Copy link
Author

@est31 Ah ok nice. How do I use that though? I tried adding it to my Cargo.toml but the results are the same (600ms) and when I compile I get a warning saying unused manifest key: profile.dev.overrides.

@est31
Copy link
Member

est31 commented Nov 4, 2020

Oh sorry the syntax has been changed. Needs to be:

[profile.dev.overrides."lewton"]
opt-level = 3

See: https://doc.rust-lang.org/cargo/reference/profiles.html#overrides

@FredrikNoren
Copy link
Author

@est31 Ah great, it's actually (for anyone else who might come here):

[profile.dev.package."lewton"]
opt-level = 3

But, that still only reduced it to 200ms, which still seems like a lot? (But I'm completely unfamiliar with how this works so could be that that's a hard limit)

@est31
Copy link
Member

est31 commented Nov 4, 2020

@FredrikNoren lol sorry, I forgot to edit it, just copy pasted it.

Yes, indeed that's what I meant.

You could also try adding such sections for crates like rodio, ogg, or just replace the "lewton" entirely with "*" to get all dependencies optimized.

@FredrikNoren
Copy link
Author

@est31 I tried it in release mode now, and even there it's 20ms. Going to try to see if I can buffer it somehow and see if it can get faster.

@FredrikNoren
Copy link
Author

I tried this: #141 (comment)

But it actually made it a bit slower; 24ms in release mode. 215ms in debug (with opt-level 3).

@est31
Copy link
Member

est31 commented Nov 4, 2020

@FredrikNoren if you really want extremely small overhead, you'll need seeking support which rodio currently doesn't support.

@FredrikNoren
Copy link
Author

@est31 Hm ok. What's missing for seeking support?

@est31
Copy link
Member

est31 commented Nov 4, 2020

@FredrikNoren backend support, see #176

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

No branches or pull requests

2 participants