Making Javascript DMP not Lock Up the Browser

128 views
Skip to first unread message

Justin Meltzer

unread,
Aug 16, 2012, 8:58:49 PM8/16/12
to diff-mat...@googlegroups.com
Due to the single threaded nature of browsers, if there is a long-running synchronous diff it will lock up the UI of the browser so that the user cannot do anything. After some benchmarking, I realized that the diff_bisect_ method is the bottleneck of the operation. I tried to make this emulate asynchrony by replacing the outer for loop with a recursive method that calls itself with setTimeout() (which generally frees up the UI of the browser). However, because all of DMP is synchronous, I'm having trouble reliably returning the diff value. I tried making the entire library callback-driven but this proved incredibly difficult. Is there a solution that I'm missing?

- Justin

Neil Fraser

unread,
Aug 16, 2012, 9:02:17 PM8/16/12
to diff-mat...@googlegroups.com
Your best bet is to use a web worker.
https://developer.mozilla.org/en-US/docs/DOM/Using_web_workers

--
Neil Fraser
http://neil.fraser.name

Justin Meltzer

unread,
Aug 16, 2012, 9:12:45 PM8/16/12
to diff-mat...@googlegroups.com, ro...@neil.fraser.name
Thanks Neil for the quick response!

I need this to work in IE (the only browser in which it seems to be locking up), which doesn't support web workers. Any other ideas? I know Google has a web worker emulator for IE that uses setTimeout, but I've already tried wrapping the method in setTimeout myself. I'm guessing each loop iteration inside diff_bisect_ will need to be wrapped in setTimeout.

Neil Fraser

unread,
Aug 16, 2012, 9:31:31 PM8/16/12
to diff-mat...@googlegroups.com
On 16 August 2012 18:12, Justin Meltzer <jus...@airtimehq.com> wrote:
> I need this to work in IE

Oh dear.

Well, IE 10 supposedly has web workers. For current versions of IE
you might want to check this out:
http://code.google.com/p/ie-web-worker/
Despite the being hosted by Google, it's not a Google product. It
also hasn't been updated in a few years, which makes me nervous...

Another approach is Google Chrome Frame, which enables IE to run Chrome:
https://developers.google.com/chrome/chrome-frame/
Of course this only works if you can get your users to install it.

Refactoring DMP to be asynchronous would be tricky. You could create
a closure at each level of recursion in diff_bisect_ but the challenge
is to resume the enclosing function. I think it would take a major
refactoring of diff_bisect_ to save state and restore from that saved
state when the answer returns.

Ge Yang

unread,
Aug 16, 2014, 2:15:17 PM8/16/14
to diff-mat...@googlegroups.com
Hey Justin,

I am thinking about using this diff library for editing as well. How is the performance on the client side? For now I don't need to support IE 10.

Thanks, 
Ge
Reply all
Reply to author
Forward
0 new messages