Repository navigation
Conversation
This improves seeking performance by reading only frame headers while looking for the frame containing the target sample. This header-only seeking can fail (e.g. because of a false sync), so the algorithm falls back to full-decode seeking in that case. Also adds tests for a newly introduced bitreader function and the seeking algorithm itself. The seeking test was used to benchmark the improvement and showed a 5-15x speedup depending on file contents and format. Authored with assistance from Claude Code Opus 5.5.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This improves seeking performance by reading only frame headers while looking for the frame containing the target sample.
I had the idea for this a few years back. We are using FLAC in our DAW products at Fender and are performing lots of seeks when users move around in projects with a large number of FLAC files. I wrote a prototype back then, but was still fighting false sync issues, so this never got adapted and the unfinished patch laid around for a few years.
I decided to revisit this now and try to finish it with AI assistance, so this was authored with help from Claude Code and the Opus 5.5 model. I was able to fix the remaining issues this way and implement a comprehensive test that doubled as a benchmark during development.
The final version of this patch reduces the number of false syncs by also looking at the frame header immediately following the current frame and only accepting the current frame if the next header agrees. There still is a very small chance for false syncs, which can cause the header-only seek operation to fail. The algorithm then falls back to full-decode seeking to ensure that any seek operation behaves the same way as without the optimization.
To quickly skip to the next possible sync point, the patch also introduces a new
FLAC__bitreader_skip_until_byte_fffunction and corresponding test.The added test/benchmark shows a 5-15x improved seeking performance, depending on file contents and format.