1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to Speed Up Javascript?

Discussion in 'BlackHat Lounge' started by agag2, Jul 30, 2013.

  1. agag2

    agag2 Supreme Member

    Joined:
    Feb 17, 2009
    Messages:
    1,308
    Likes Received:
    254
    Hello

    I'm running a program in Firefox that sifts through 100's of thousand of numbers (or millions perhaps) and so far it's running for about 2 hrs. Is there any way to speed up performance?

    Thanks
     
  2. cnick79

    cnick79 Jr. VIP Jr. VIP

    Joined:
    Jun 10, 2010
    Messages:
    653
    Likes Received:
    341
    Location:
    Google's SandBox
    JavaScript is all client side meaning it runs in your browser using your computer resources. There are ways to speed up the code, but that would require rewriting it. Is this your code, or somebody else?
     
  3. cyrix

    cyrix Junior Member

    Joined:
    Sep 19, 2008
    Messages:
    179
    Likes Received:
    61
    Occupation:
    Full Time Internet Marketer\Developer
    Location:
    United States
    Try using a browser that executes and runs JavaScript faster then firefox or have the application re-coded to use server side processing and a database to browse the data. When I write a new application I usually use just JavaScript for tables because its faster to implement but if the table will be working with thousands or even millions of records the heavy lifting should be handled server side via the database as it is immensely faster.
     
  4. Fxbob

    Fxbob Junior Member

    Joined:
    Feb 21, 2011
    Messages:
    154
    Likes Received:
    342
    Delegate processing to a remote server using Ajax and simply receive the results back, use javascript as the controller/manager, not the executor; javascript is not designed for heavy number crunching.
     
  5. agag2

    agag2 Supreme Member

    Joined:
    Feb 17, 2009
    Messages:
    1,308
    Likes Received:
    254
    It is my code but I hired someone to write it. Rewriting it would cost me several hundred dollars. I assume that if I do rewrite it, C++ would be the best choice to speed up performance?
     
  6. agag2

    agag2 Supreme Member

    Joined:
    Feb 17, 2009
    Messages:
    1,308
    Likes Received:
    254
    Thanks for your reply.

    Would this speed up the execution itself or just free up my computer resources (shift resources from my computer to remote server)?
     
  7. Fxbob

    Fxbob Junior Member

    Joined:
    Feb 21, 2011
    Messages:
    154
    Likes Received:
    342
    It would do both, just batch up your calculations to reduce latency/round trip time.
     
  8. agag2

    agag2 Supreme Member

    Joined:
    Feb 17, 2009
    Messages:
    1,308
    Likes Received:
    254
    By how much would Ajax speed up the code? Also if I want to hire someone to do this what would I ask them - to convert javascript into Ajax?
     
  9. Fxbob

    Fxbob Junior Member

    Joined:
    Feb 21, 2011
    Messages:
    154
    Likes Received:
    342
    Ajax would be simply delegating the work to a remote server, so speed would depend on the language used on that server, how optimized the remote code is, and the overall performance of the server. Other factors that may contribute to speed is latency, or the time it takes to send a given request/task to be executed. You can reduce latency by batching up operations (sending more tasks to be executed within each request).

    In short, you convert your javascript into a client that delegates work instead of executing it.
     
    • Thanks Thanks x 1
  10. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    What is this program doing that needs to be calculation heavy and had to be executed on a browser?
     
  11. agag2

    agag2 Supreme Member

    Joined:
    Feb 17, 2009
    Messages:
    1,308
    Likes Received:
    254
    Well, it didn't need to be executed in the browser but for some reason my programmer wrote it in PHP + Javascript so I believe this is the only way to run the script (is this correct?).
     
  12. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    Since he wrote it that way, yes.