Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28580 > unrolled thread
| Started by | "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> |
|---|---|
| First post | 2015-08-29 16:11 -0700 |
| Last post | 2015-08-30 22:21 +0200 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.javascript
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
| From | "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> |
|---|---|
| Date | 2015-08-29 16:11 -0700 |
| Subject | Performance question |
| Message-ID | <dje4uadokf3hpfi2e702t404088avf2d49@4ax.com> |
I'm attempting to optimize a lengthy ECMA script for speed. Please
pardon my ignorance...
I have multiple instances of document.getElementById('id').checked or
value.
Q1: When running the script, does it search through a table for the
address, or does it only do it once during compilation?
Q2. Moot if Q1 answer is 'only once.' 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?
Thanks in advance for helping and not beating me up.
--
Joey
[toc] | [next] | [standalone]
| From | "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> |
|---|---|
| Date | 2015-08-30 09:50 -0700 |
| Message-ID | <g1d6uatb43i5dqa7mdtg1kpktaacof90bm@4ax.com> |
| In reply to | #28580 |
On 29 Aug 2015 23:24:49 GMT, ram@zedat.fu-berlin.de (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.
Thank you.
--
Joey
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2015-08-30 22:16 +0200 |
| Message-ID | <6778316.kWqCXO56M2@PointedEars.de> |
| In reply to | #28580 |
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.
--
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.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2015-08-30 22:21 +0200 |
| Message-ID | <2476408.3rOYMglltH@PointedEars.de> |
| In reply to | #28585 |
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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web