Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

8. WebWorker API > Hack 65. Perform Heavy Array Computations in a Dedicated Web...

Hack 65. Perform Heavy Array Computations in a Dedicated Web Worker

Dedicated web workers are a great solution for expensive computations such as array manipulation. With this hack you can move such a computation to a worker without impacting the performance of an interactive canvas animation in the main thread.

To begin to understand the power of web workers we need to manufacture an expensive operation, and create a UI that uses some type of animation that we would like the user to be able to interact with seamlessly.

For the expensive operation we can manipulate array data, and for the animation we can create a simple canvas that has balls bouncing as the user interacts with it.

We will then provide a simple UI that provides tools for testing heavy array manipulation inside and outside a web worker. The test will be focused on the user experience. We will not output data to show the performance of our code, but we will rely on the popular concept of perceived performance to determine which solution is higher performing.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint