Fix/parser and search perf#23
Open
abdelaziz-mahdy wants to merge 3 commits intodsc-uob:masterfrom
Open
Conversation
Subtitle load failures used to vanish into zone error handlers — the provider fire-and-forgets `initial()`, so a bad URL, non-200, or unsupported extension produced silent "no subs rendered" with no breadcrumbs. Now every fetch logs url/scheme/host/extension/header-keys, every response logs status + body head, every exception logs with stack, every zero-match parse logs body head + detected type, and UnsupportedSubtitleFormat logs the rejected extension. Uses `dart:developer.log(name: 'subtitle')` so nothing new shows up for consumers by default — only when they attach DevTools or tail `flutter run` output.
The previous regex-driven VTT/SRT parser had nested unbounded quantifiers and could backtrack for tens of seconds on pathological inputs (e.g. 16k-cue karaoke VTTs from kaa.mx). multiDurationSearch was also O(n) per call, which then dominated the UI thread on every position event. Three changes: - Replace the VTT/SRT regex match with a hand-rolled cue-block parser that tokenizes the file into blank-line-separated blocks and only regex-matches each timing line. Linear time, no backtracking. TTML/DFXP keep the regex path. - After parsing, collapse identical-time cues to the longest text and merge contiguous identical-text cues. Karaoke files shrink from ~16k cues to a few hundred without losing visible content. - Rewrite multiDurationSearch as upper_bound on start + backward walk bounded by a precomputed prefix-max-end array (O(log n + k)). Validated on a 733KB / 16k-cue VTT: parse+sort+cleanup 67s -> 126ms, 539 cues remain, 1000 searches in <1ms. Test added uses a synthetic karaoke VTT generated in-memory.
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.
No description provided.