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

  • Home
  • SEARCH
  • 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 8600203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:33:53+00:00 2026-06-12T01:33:53+00:00

I quite often have optional arguments in functions, but some testing is showing a

  • 0

I quite often have optional arguments in functions, but some testing is showing a huge performance hit for them in firefox and safari (70-95%). Strangely, if I pass in the literal value undefined then there is no penalty. What could be happening here? I wouldn’t have thought that it was a scope chain issue as they are inherently local to the function. Am I to start passing undefined into every optional argument?

jsPerf: http://jsperf.com/function-undefined-args/2

  • 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-12T01:33:54+00:00Added an answer on June 12, 2026 at 1:33 am

    For a function like this:

    function threeArgs(x, y, z) {
      return x + y + z;
    }
    

    that’s called like this:

    threeArgs(1, 2, 3);
    

    the optimizer is free to make the choice to generate no code at all. It’s fairly easy for it to determine that there are no side effects, because the function simply references its parameter values and returns the result of a simple expression. Since the return value is ignored, there’s no reason for the runtime to do anything at all.

    Beyond that, if the code were:

    something += threeArgs(1, 2, 3);
    

    the optimizer might decide to generate code roughly equivalent to:

    something += 6;
    

    Why? Because the call was made with numeric constants, and it can safely fold those at code generation time. It might be conservative on that, because numbers are weird, but here they’re all integers so it could well do this. Even if it didn’t, it could safely inline the function:

    something += 1 + 2 + 3;
    

    When there’s a parameter missing, however, it may be that the optimizers bail out and generate a real function call. For such a simple function, the overhead of the function call could easily account for a large difference in performance.

    By using variables instead of constants in a test, and by actually using the return value of the function, you can “confuse” the optimizer and keep it from skipping the call or pre-computing the result, but you can’t keep it from inlining. I still think that your result is interesting for that reason: it exposes the fact that (as of today anyway) those optimizers are sensitive to the way that functions are invoked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I quite often have to bind? some function that requires arguments. The solution I
In error reports from some end users of our game I have quite often
I have quite often some very long console commands like: python /var/www/closure-library/closure/bin/calcdeps.py \ -i
I have been looking into custom allocators and I quite often see them using
I quite often have rows of code like the following: UPDATE my_table SET name
Python and Matlab quite often have integer date representations as follows: 733828.0 733829.0 733832.0
I have a bare repository I access over a SMB network. Quite often I
I ran into this quite often stated problem but even after looking up nearly
I have the following boilerplate that I do quite often, and would like to
I use a binary library that crashes quite often. When it does, some times

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.