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

flac, isomp4, mkv: optimize length detection by using byte_len() instead of seeking #340

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

roderickvd
Copy link

Replace seeking to end of file with byte_len() call to get total stream length. This improves performance when streaming files by avoiding an unnecessary seek operation. The change maintains the same functionality while being more efficient, especially for remote/streaming files where seeks are expensive.

As used in pleezer, previously seeking would block the application until the full file was downloaded, even if the position seemed to was already buffered. With this change, such seeks are nearly instantaneous.

Optionally, we could first try byte_len() and fall back to seeking to the end when byte_len() is not available.

The actual change is just three lines, but my editor automatically fixed some minor code formatting issues with else clauses. Nothing more than rustfmt.

…ead of seeking

Replace seeking to end of file with byte_len() call to get total stream
length. This improves performance when streaming files by avoiding an
unnecessary seek operation. The change maintains the same functionality
while being more efficient, especially for remote/streaming files where
seeks are expensive.

Also fixes some minor code formatting issues with else clauses.
roderickvd added a commit to roderickvd/pleezer that referenced this pull request Jan 16, 2025
Uses a patched version of Symphonia that improves seeking performance
in FLAC and MP4 files by using the known file byte length instead of
seeking to the end of file to determine length.

This is a temporary patch that will be removed once
pdeljanov/Symphonia#340 is merged upstream.
@pdeljanov
Copy link
Owner

pdeljanov commented Jan 18, 2025

Hi @roderickvd, yeah, that's the way it should've been. Nice find!

The reason you got so many formatting changes is because we need the nightly rustfmt to use the brace style option. Are you able to run that with cargo +nightly fmt?

By the way, please keep an eye on the dev-0.6 branch as that will be the future of Symphonia in a little while.

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.

2 participants