Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9017701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:20:21+00:00 2026-06-16T04:20:21+00:00

I am doing heavy canvas operations in a jQuery each loop causing slower devices

  • 0

I am doing “heavy” canvas operations in a jQuery each loop causing slower devices (IE and the iPad) to sometimes become totally unresponsive.

So I was thinking I could use underscore’s _.defer() to queue the functions in my each loop like:

function handleAsset = _.defer(function(){
//weightlifting goes here (partly async)
});

$.each(assets, handleAsset);

Yet this throws a weird error (the stack trace points to the $.each):

Uncaught TypeError: Object 20877 has no method 'call'

Is this approach flawed? Is this due to async operations going on inside the handler function? Is there another / a better way to achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:20:23+00:00Added an answer on June 16, 2026 at 4:20 am

    It is flawed. You should try to decouple / break up code at the lowest point possible. I think its unlikely that just decoupling each iteration of a loop is enough on the long run.

    However, what you really need to do is, to setup an asyncronous runaway timer which gives the implementation enough room to update the UI Queue (or UI thread). This typically is done using methods like setTimeout() (client), nextTick (node.js) or setImmediate (coming soon).

    For instance, lets say we have an array, and we want to process each entry

    var data = new Array(10000).join( 'data-' ).split('-'); // create 10.000 entries
    
    function process( elem ) {
        // assume heavy operations
        elem.charAt(1) + elem.charAt(2);
    }
    
    for(var i = 0, len = data.length; i < len; i++ ) {
        process( data[i] );
    }
    

    Now this code is a classic loop, iterating over the array and process its data. It’ll also consume 100% CPU time and will therefore block the browsers UI queue as long as it takes to process all entries (which basically means, the browser UI will freeze and become unresponsive).

    To avoid that, we could create a construct like this:

    var data  = new Array(10000).join( 'data-' ).split('-'); // create 10.000 entries
    
    function runAsync( data ) {
        var start = Date.now();
    
        do {
            process( data.shift() );
        } while( data.length && Date.now() - start > 100 );
    
        if( data.length ) {
            setTimeout( runAsync.bind( null, data ), 100 );
        }
    }
    
    runAsync( data.concat() );
    

    What happens here ?

    What we’re basically doing is:

    • Take the array and process as much data/entries as possible within a timeframe of 100ms
    • After that, stop processing (call setTimeout) and give the UI a chance to update
    • do that as long as we still have data in the array

    Any delay above 100 ms is typically recognized by the human eyes as “lag“. Anything below that seems fluently and nice (at least our eyes will tell us so). 100ms is a good value as limit for maximum processing times. I’d even suggest to go down to 50ms.

    The caveat here is that the overall processing time will increase, but I think its a better deal to have longer processing and stay responsive, instead faster processing and a very bad user experience.


    Quick Demo:

    • classic iteration (move the red square around, will block)
    • runaway script timer (move the red square around, will be possible)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing heavy computation using the GPU, which involves a lot of render-to-texture operations.
I basically have a unix process running and it is doing some heavy processing
Doing some jquery animation. I have certain divs set up with an attribute of
I'm doing some heavy processing (building inverse indices) using ints/ longs in Java. I've
My FlashBuilder instance keeps on crashing while doing some heavy profiling. Must say though
I am using criterion to benchmark my Haskell code. I'm doing some heavy computations
In C++ doing heavy lifting in the constructor is discouraged for, amongst other things,
I'm doing some pretty processor heavy processing on a few audio files. Before I
I'm doing some heavy image manipulation in php and I would like to show
I am developing an Android app and I am doing some heavy work (bringing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.