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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:24:56+00:00 2026-05-29T13:24:56+00:00

Recently I’ve read this performance guide Let’s make the web faster and was puzzled

  • 0

Recently I’ve read this performance guide Let’s make the web faster and was puzzled by “Avoiding pitfalls with closures” recommendations (as if these advices were given for CommonLisp users where variable scoping is dynamic):

var a = 'a';
function createFunctionWithClosure() {
  var b = 'b';
  return function () {
    var c = 'c';
    a;
    b;
    c;
  };
}

var f = createFunctionWithClosure();
f();

when f is invoked, referencing a is slower than referencing b, which is slower than referencing c.

It’s quite evident that referencing local variable c is faster than b, but if the iterpreter is written properly (without dynamic scoping – something like chained hashtable lookup..) the speed difference should be only marginal. Or not?

  • 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-29T13:24:57+00:00Added an answer on May 29, 2026 at 1:24 pm

    You’re right. Modern JS engines will optimize the scope chain lookup and the prototype chain lookup like a lot. Means, AFAIK the engine trys to hold some sort of hash-table with access nodes underneath.

    This only works if there is no eval() (explicity or implicitly, e.g. setTimeout) or a try-catch clause or a with statement invoked. Because of such constructs, the interpretator can’t be sure about how to access data and it needs to “fallback” into a classical scope chain lookup which really means, it has to crawl through all parent context variable / activation objects and try to resolve the searched variable name.
    This process of, of course, will take more time for objects/names which are located “far away” from where the lookup processed was started. That in turn means, that accessing data on the global object will always be the slowest.

    In your snippet, the lookup process for a would go like

    anonymous function -> Execution Context -> Activation Object (not found)
    anonymous function -> Execution Context -> [[ Scope ]] 
        - createFunctionWithClosure
        - global scope
    createFunctionWithClosure -> Activation Object (not found)
    global scope -> Variable Object (found)
    

    The described lookup procedure is for ECMAscript Edition 262 3rd edition. ECMAscript edition 5 has some fundamental changes there.

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

Sidebar

Related Questions

Recently I ran into this error in my web application: java.lang.OutOfMemoryError: PermGen space It's
Recently I was confused by this question . Maybe because I didn't read language
Recently I read this Wikipedia article regarding the Dining Philosophers problem but I am
Recently, I read an article entitled SATA vs. SCSI reliability . It mostly discusses
Recently two users of our software from the same company started experiencing random closures
Recently, I came across this one stone kills multiple birds framework - http://phonegap.com/ .
Recently I found about this tool easy_install that help me to easy install additional
Recently I started working with RAD and WebSphere on development of web services and
Recently I asked this question: Find Common Values in several arrays, or lists VB.NET
Recently, we discovered odd behavior in some old code. This code has worked for

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.