Cache Matroska subtitle tracks across track switches#11624
Open
HellbringerOnline wants to merge 1 commit into
Open
Cache Matroska subtitle tracks across track switches#11624HellbringerOnline wants to merge 1 commit into
HellbringerOnline wants to merge 1 commit into
Conversation
31e6977 to
4860c31
Compare
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.
Summary
This PR reduces repeated reads of the same Matroska file when working with embedded subtitle tracks.
The main change is in
MatroskaFile.GetSubtitle(...): the first subtitle extraction now scans the Matroska clusters once and caches subtitle blocks for all subtitle tracks in memory, keyed by Matroska track number. Later requests for any subtitle track on the sameMatroskaFileinstance reuse that cache instead of scanning the file again.Why
The
Pick Matroska trackdialog previews subtitle tracks by callingGetSubtitle(...)when the selected row changes. Before this change,MatroskaFileonly cached the most recently requested track. Selecting track A, then B, then A again caused another full scan of the MKV for A. The same repeated read also showed up when the selected track was loaded after previewing it.This is especially noticeable with large
.mkvfiles because every track switch can turn into another read through the container.What changed
MatroskaFileinstance.GetSubtitle(int trackNumber, LoadMatroskaCallback progressCallback)API unchanged.GetSubtitle(...)calls for HDMV TextST preview/export paths where the subtitles list had already been loaded.The cache remains scoped to the lifetime of a
MatroskaFileinstance and is released when that instance is disposed.Known remaining behavior
There is still another related scenario outside this PR: after selecting an image-based MKV track and opening the OCR window, pressing
Edit/ExportopensEdit image-based subtitle. That path currently passes both the source file name and the already extracted OCR subtitle data toBinaryEditViewModel, butBinaryEditViewModelreloads the file when a file name is present. For multi-track or large MKV files this can showPick Matroska trackagain and trigger another Matroska read.That behavior is significant for large files, but it is a separate handoff/lifetime issue between the OCR and BinaryEdit windows. This PR keeps the scope limited to improving repeated reads within a single
MatroskaFileinstance.Validation
Ran locally:
dotnet test tests\\libse\\LibSETests.csproj --no-restoreAlso checked on the newer upstream-based branch before preparing this fork-compatible PR branch:
dotnet test tests\\libse\\LibSETests.csproj --no-restoredotnet test tests\\libuilogic\\LibUiLogicTests.csproj --no-restoredotnet build src\\UI\\UI.csproj --configuration Release --no-restoreOn this older fork base,
tests/UI/UITests.csprojandsrc/UI/UI.csprojhit existing package/project setup issues unrelated to this change (xUnit v3 OutputTypeand missing UI package references without refreshing the lock/restore state), so I did not include lockfile updates in this PR.