mozilla / vtt.js

A JavaScript implementation of the WebVTT specification
http://dev.w3.org/html5/webvtt/
Apache License 2.0
484 stars 94 forks source link

vttjs takes a long time (1s) to parse really long files, isn't optimized by engines #340

Open gkatsev opened 9 years ago

gkatsev commented 9 years ago

If you use a really large webvtt file (like here http://jsbin.com/hewamuwali/1/edit?html,output, with 1553 cues), vttjs takes around 1 second to parse the file. One of the reasons is that the parse function uses a lot of try/catches and some engines (for example, v8) do not optimize these functions, so, they never run as fast as possible. Also, this function runs synchronously rather than asynchronously. This means that if it takes a long time to parse the file, everything else in the application will hang. The parse function should be broken up to chunk processing of the file asynchronously to hand back execution time to the page. Also, try/catches should either be wrapped or removed altogether.

heff commented 9 years ago

FYI, the video won't work in the linked jsbin because flash isn't supported there, you need to go to the preview version o the bin. http://output.jsbin.com/kopuqizomo/1

@gkatsev the captions don't show at all in those examples. Is that expected?

I definitely see the drag though, in Chrome and Safari. What do you mean by chunk processing, specifically? Just dropping a setTimeout(fn, 0) around some of the bulky operations?

gkatsev commented 9 years ago

They start at around 27 seconds.

Basically, process a bit of the file at a time. Around 100-200ms at a time or maybe like 30 cues. And wrap each chunk in a setTimeout.

gkatsev commented 9 years ago

@RickEyre any thoughts on this? Thanks!

altaywtf commented 7 years ago

hi guys, any updates/workarounds about this?