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 6714185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:27:57+00:00 2026-05-26T08:27:57+00:00

nowadays i am optimizing some js code. there is a function named appendXYZ,and it

  • 0

nowadays i am optimizing some js code.
there is a function named appendXYZ,and it is invoked in a loop with other functions.
it looks like as the following:

function OuterFunc (){
  for(...){// about 150 times
     ...
     appendXYZ();
     //other dependent functions
     ...
  }
}

and now i am pretty sure that appendXYZ cause high cpu usage – it can reach 50%,
but if i remove this function,cpu usage is only 1%.
when the cpu usage is 50%,the browser is nearly frozen and the page is lack of responsiveness.
what is more ,the OuterFunc execute every 20 seconds and appendXYZ is from a third party script code and i cant modify it.
so how to optimize this code?

now i am trying to use setTimeout but i dont know whether it works.

  • 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-05-26T08:27:58+00:00Added an answer on May 26, 2026 at 8:27 am

    I don’t know what that function does, but you could try making its invocation asynchronous.

    It may or may not work, and it will still require the same amount of CPU, but it should at least free up the browser a bit.

    function OuterFunc (){
      for( var i = 0; i < 150; i++ ){
         // ...
         setTimeout( appendXYZ, 0 );
         //other dependent functions
         // ...
      }
    }
    

    Again this may break the function. Can’t tell without seeing more code.

    If you’re passing arguments, then you’d need something like:

    function invoker( j ) {
       return function() {
           appendXYZ( j );
       };
    }
    
    function OuterFunc (){
      for( var i = 0; i < 150; i++ ){
         // ...
         setTimeout( invoker( i ), 0 );
         //other dependent functions
         // ...
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seems like more companies are using Ruby on Rails nowadays. What are some other
Nowadays I see in some developers, use function named GetAll or Getlist in each
Nowadays we have screens like 1920x1200 and 1680x1050 in popular use and some even
Nowadays most of the Restaurants and other businesses have a Find Locations functionality on
I am studying usage of web services nowadays. Can anyone recommend some free web
nowadays I have this piece of code: #import C:\Users\Public\SoundLog\DLLs\ForPython\SoundLogDLL.tlb named_guids but I want to
When you learn HTML and so forth nowadays, the mantra is always Clean code
nowadays you can read much about code injection, exploits, buffer-, stack- and heap-overflows etc.
In my work I deal mostly with C# code nowadays, with a sprinkle of
I've written some amounts of LaTeX but nowadays I'm feeling lazy and I would

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.