Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28587

Re: Performance question

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Performance question
Date 2015-08-30 22:21 +0200
Organization PointedEars Software (PES)
Message-ID <2476408.3rOYMglltH@PointedEars.de> (permalink)
References <dje4uadokf3hpfi2e702t404088avf2d49@4ax.com> <performance-20150830002413@ram.dialup.fu-berlin.de> <6778316.kWqCXO56M2@PointedEars.de>

Show all headers | View raw


Thomas 'PointedEars' Lahn wrote:

> Stefan Ram wrote:
>> "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> writes:
>>>                                      If I declare a global variable
>>>as 'var xxx = document.getElementById('id'),' and use it throughout
>>>the script as 'xxx.value or xxx.checked,' does this improve
>>>performance?
>> 
>>   One does indeed expect such an improvement, but the
>>   best thing is to measure it under different browsers.
> 
> There is no good reason to believe that omitting a function call in favor
> of a variable access would not improve performance.  It is unnecessary to
> measure this.

Also, the variable may be declared, but the reference to the object should 
be passed to functions and methods by parameter, which should be accessed 
instead.  This shortens the effective scope chain and improves performance 
again.

The module pattern even removes the need for the variable to be declared 
global.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Performance question "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2015-08-29 16:11 -0700
  Re: Performance question "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2015-08-30 09:50 -0700
  Re: Performance question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-30 22:16 +0200
    Re: Performance question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-30 22:21 +0200

csiph-web