Main thread blocked by javascript

28 views
Skip to first unread message

John Freeman

unread,
Feb 9, 2016, 6:01:57 AM2/9/16
to Native-Client-Discuss
Is there any way to make the main thread continue execution if the web page is busy performing operations?

For example, I have a PPAPI video player showing HLS content, and the web page that is serving it is currently busy fetching data. This causes the video playback in the plugin to periodically freeze.

The same can be seen if you use the graphics3D example and add a button that causes the page to be busy for example:

<body>

 <embed name="nacl_module1" id="nacl_module1" width="320" height="240" path="pnacl/Release" src="pnacl/Release/graphics_3d.nmf" type="application/x-pnacl">
   <script>
function freeze() {
var start = new Date().getTime();
        while (new Date().getTime() < start + 1000);
}
</script>
 <button onClick="freeze();"> Slow </button>

  <div id="listener"></div>
</body>


Ben Smith

unread,
Feb 9, 2016, 2:04:47 PM2/9/16
to Native-Client-Discuss
Hi John,

Yes, I see this behavior too. AIUI, the problem is that if you are blocking the JavaScript event loop, you prevent anything that needs to access the DOM from running. If you run your code on another Native Client thread, it will continue to run even when the JavaScript/DOM thread is blocked. But as soon as you need to communicate with that thread, it will block. I tested adding your "slow" button to the life example (which runs everything on a separate thread), and it had the same problem.

I think the only solution you have here is to make sure that you don't do too much work in one turn of the event loop. Networking shouldn't cause this problem, but perhaps your processing of the network data does? If so, perhaps you can split the work over multiple turns.

-Ben

John Freeman

unread,
Feb 10, 2016, 5:32:24 AM2/10/16
to Native-Client-Discuss
Thank you, that makes sense. We do a lot of processing of the data as you said, so I will have to do some refactoring in the javascript.

Thanks

John
Reply all
Reply to author
Forward
0 new messages