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

improve performance and seek accuracy #48

Merged
merged 4 commits into from
Jan 4, 2024
Merged

improve performance and seek accuracy #48

merged 4 commits into from
Jan 4, 2024

Conversation

BillyDM
Copy link

@BillyDM BillyDM commented Jan 3, 2024

I discovered that the new safe code could perform worse when decoding near the end of a file. It would zero-out blocks even if those blocks contained no data. So I fixed that.

Since fixing this required a change inside ReadDiskStream::read(), I also went ahead and cleaned up that method by consolidating redundant code into a closure.


I also noticed that the seeking accuracy in the Symphonia decoder could be improved, so I also did that. Ideally Symphonia should have a method to request an exact frame to seek to, but for now this should be better.

Note this change does not fix #43. I plan to look into that in a different PR.

Also another side note, I noticed that for some reason I used usize for the value of frames instead of u64. The whole point of disk streaming is to support very long files, and usize would potentially be too limiting on 32 bit platforms. But changing this would be a breaking change, so I'll wait to fix that in a different PR.

@BillyDM BillyDM requested a review from orottier January 3, 2024 21:47
Copy link
Collaborator

@uklotzde uklotzde left a comment

Choose a reason for hiding this comment

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

I didn't check the details but the changes look reasonable. Eliminating the duplicated parts of the code is really helpful.

@@ -756,58 +756,84 @@ impl<D: Decoder> ReadDiskStream<D> {
reached_end_of_file = true;
}

let copy_block_into_read_buffer =
Copy link
Collaborator

@uklotzde uklotzde Jan 3, 2024

Choose a reason for hiding this comment

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

Why not extract this function at the module level instead of using a local closure?

Copy link
Author

Choose a reason for hiding this comment

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

Since it is only used by this one method, I think it makes sense to use a closure. But if you think it would be more readable as a function, we could do that.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I extracted it into a function and did that let-else thing. You're right, I think it is easier to read that way.

block_index: usize,
start_frame_in_block: usize,
frames: usize| {
let maybe_block = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using let-else statements with early returns might improve the readability.

Copy link
Author

Choose a reason for hiding this comment

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

Oh, I didn't know Rust had let-else statements. Awesome, learn something new every day.

@BillyDM
Copy link
Author

BillyDM commented Jan 3, 2024

Oh wait, let-else statements were only stabilized in version 1.65, but creek has set its minimum supported version 1.62.

Since bumping the minimum supported version probably breaks semver, I'll remove it.

@uklotzde
Copy link
Collaborator

uklotzde commented Jan 3, 2024

Oh wait, let-else statements were only stabilized in version 1.65, but creek has set its minimum supported version 1.62.

Since bumping the minimum supported version probably breaks semver, I'll remove it.

What's the reasoning for keeping creek backwards compatible with 1.62?

@BillyDM
Copy link
Author

BillyDM commented Jan 4, 2024

What's the reasoning for keeping creek backwards compatible with 1.62?

I'm not sure actually. Was it @orottier or @Be-ing that added that?

@Be-ing
Copy link
Collaborator

Be-ing commented Jan 4, 2024

Go ahead and bump the minimum Rust version if it's helpful (which it is in this case).

@Be-ing
Copy link
Collaborator

Be-ing commented Jan 4, 2024

Since bumping the minimum supported version probably breaks semver, I'll remove it.

MSRV increase is not a semver breaking change.

@orottier
Copy link
Collaborator

orottier commented Jan 4, 2024

I'm fine with bumping MSRV. I have not encountered anyone in the wild using pre 1.65 versions

Copy link
Collaborator

@orottier orottier left a comment

Choose a reason for hiding this comment

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

LGTM

@BillyDM
Copy link
Author

BillyDM commented Jan 4, 2024

MSRV increase is not a semver breaking change.

Oh it's not? Okay, I'll bump the version and merge this then.

@BillyDM BillyDM merged commit 9f2414e into main Jan 4, 2024
4 checks passed
@BillyDM BillyDM deleted the improve_performance branch January 4, 2024 23:33
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.

The Symphonia decoder ignores the actual seek position, resulting in audible glitches in file playback
4 participants