Skip to content

Fix/parser and search perf#23

Open
abdelaziz-mahdy wants to merge 3 commits intodsc-uob:masterfrom
abdelaziz-mahdy:fix/parser-and-search-perf
Open

Fix/parser and search perf#23
abdelaziz-mahdy wants to merge 3 commits intodsc-uob:masterfrom
abdelaziz-mahdy:fix/parser-and-search-perf

Conversation

@abdelaziz-mahdy
Copy link
Copy Markdown
Contributor

No description provided.

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.
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.

1 participant