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


Groups > comp.lang.javascript > #28587

Re: Performance question

Path csiph.com!eternal-september.org!feeder.eternal-september.org!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Performance question
Supersedes <23254603.3H0zayOWXO@PointedEars.de>
Date Sun, 30 Aug 2015 22:21:35 +0200
Organization PointedEars Software (PES)
Lines 29
Message-ID <2476408.3rOYMglltH@PointedEars.de> (permalink)
References <dje4uadokf3hpfi2e702t404088avf2d49@4ax.com> <performance-20150830002413@ram.dialup.fu-berlin.de> <6778316.kWqCXO56M2@PointedEars.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Trace solani.org 1440966306 31587 eJwNyskBwDAIA7CVOGwo4xQa9h8h1Vv00JhEMMDlZlqSWko9LQefpTketJfgHSzD5c+tFB+pC/J4D3k= (30 Aug 2015 20:25:06 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Sun, 30 Aug 2015 20:25:06 +0000 (UTC)
User-Agent KNode/4.14.2
Cancel-Key sha1:yknejyqJlssQmno5KqncMoF2Bzo=
X-User-ID eJwNwokRwCAMA7CV8jphnEDx/iOUk9KhOBVIRPLZV+hWFOlIlFIu15bDsHFh46s3wem1ckYN1p/LGa1b/AFG6xU8
Cancel-Lock sha1:lmLNixhlHyK5D68t1tfnQEab9dE=
X-NNTP-Posting-Host eJwNyMkBwCAIBMCW5NgVykGU/ktI5jkwCns7QcdgonfNPwU14o5IaZq3VrzphYWSfDwVJ+N6fB+aETE=
Xref csiph.com comp.lang.javascript:28587

Show key headers only | 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