← Back to team overview

launchpad-dev team mailing list archive

Re: YUI "issue" under Windmill

 

On Wed, Nov 17, 2010 at 12:11 PM, Paul Hummer <paul.hummer@xxxxxxxxxxxxx> wrote:
> Yeah, this is a lie.  Namespacing in javascript is a lie in general,
> because ECMAScript keeps a scope chain, not a namespace.  The more
> periods you have in your variable, the slower the access is going to be,
> and so our "namespacing" is actually causing things to be slower
> (although it's probably not the immediate performance focus).

To rephrase this more clearly, the more scope lookups have to be
performed, the slower it will be. However, unless you're accessing a
deep namespace inside a loop, the impact is negligible.

For performance *and* minification reasons, it's good practice to make
local aliases to anything that's more than one or two levels deep in
namespacing, specially if you're going to use it inside a loop. For
example:

  var isNull = Y.Lang.isNull;

  for (...) {
     if (isNull(...)) {
        // do stuff
     }
  }

For more information on the subject of scope lookup impact on
Javascript performance and a comparison between the different
browsers, I highly recommend Nicholas Zakas' High Peformance
Javascript. HINT: it matters more for older browsers, and might be
negligible for anything up to 4 levels deep scoping in the near future
with V8 and Jagermonkey.

-- Sidnei



References