#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2009
    Posts
    3
    Rep Power
    0

    Looking for opinions


    I've done quite a bit of research on optimization of JavaScript, and the following seem to be pretty widely regarded as facts:

    1. Function expressions run slower than function declarations.

    2. Local variables are faster than global

    3. Prototype can save resource use in certain cases

    My question is this: at what point would you say prototype use would become worthwhile, given the fact that it requires the use of function expressions, and is not evaluated until runtime, and therefore runs more slowly? It also makes code more bloated. How many instances of a function would you say would be required to make prototyping noticeably the better option? Thanks in advance
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    I sort of doubt anyone is going to know the answer to that question, that level of optimization is far more than is needed for 99% of projects. The answer is probably different for every JavaScript engine too. What are you building that requires such a high degree of optimization?
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2009
    Posts
    3
    Rep Power
    0
    Hi, it's less about what I'm building and more about disputing a general practice where I work. In the shop I'm currently employed at, pretty much every function is prototyped, and I strongly believe that in most cases this is not only wasteful in terms of bulk of code, but also actually less efficient and slower. I just wanted to see if anybody else had an opinion.

    What I've discovered in writing for mobile devices, particularly older, slower ones, is that even the practice of name spacing, which adds an extra layer to the scope chain, has a performance affect in some of these older and pathetic processors.

    If you're working with devices that slow, even using a function expression as opposed to a declaration taxes them too much. Having them try to evaluate and execute the code at runtime is simply too much for these little things.

    But regardless of what device you're writing for, it would still mean that these practices are actually slower overall. You may not notice them on desktop, or newer mobile devices, but I think if they were bench tested, it would show up. You can find some of these tests on JSperf. Thanks for your reply-AC

IMN logo majestic logo threadwatch logo seochat tools logo