Closed
Bug 516900
Opened 16 years ago
Closed 1 year ago
Repeated call to document.getElementById is slower in firefox than Safari.
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
People
(Reporter: BijuMailList, Unassigned)
References
Details
(Keywords: perf, testcase)
Attachments
(1 file)
4.06 KB,
text/html
|
Details |
Repeated call to document.getElementById is slower in firefox than Safari.
function $(id, refresh) {
if (typeof id == "string") {
id = !refresh && $[id] || ($[id] = document.getElementById(id));
}
return id;
}
function dd($) {
var _$ = document;
_$.$ = _$.getElementById;
var i, d1, d2, d3, d4, d5, id = "alink", k = 1000000; //ie. 1,000,000
function __(id) {return document.getElementById(id);}
d1 = new Date;
for (i = 0; i < k; i++) _$.$("alink");
d2 = new Date;
for (i = 0; i < k; i++) __("alink");
d3 = new Date;
for (i = 0; i < k; i++) $("alink");
d4 = new Date;
for (i = 0; i < k; i++)$[id]||$(id);
d5 = new Date;
for (i = 0; i < k; i++)$["alink"]||$("alink");
d6 = new Date;
for (i = 0; i < k; i++)$.alink ||$("alink");
d7 = new Date;
return [d2 - d1, d3 - d2, d4 - d3, d5 - d4, d6 - d5, d7 - d6];
}
dd($);
I ran above code on various PC and got following result.
And here is the summary of what I observed.
1. Safari is doing some kind of caching like
I do with my $() function and beat Firefox on speed
2. Namoroka/Trunk build executing shorter code ie _$.$()
slower than calling my javascript function __()
which in turn call getElementById
3. On slower PC in some case Shiretoko is faster than Minefield
====== PC 1 =========
Loop Count : 1000000 //ie. 1,000,000
Safari 4
Result : 165,293,223,101,98,15
Namoroka/3.6a2pre
Result : 1792,1356,312,109,70,70
====== PC 2 =========
Loop Count : 1000000 //ie. 1,000,000
Gecko/20090915 Minefield/3.7a1pre
Result : 1354,559,335,71,10,9
Gecko/20090915 Namoroka/3.6a2pre
Result : 1312,583,361,67,13,9
Gecko/20090915 Shiretoko/3.5.4pre
Result : 1931,3866,346,108,10,11
====== PC 3 =========
Loop Count : 300000 //ie. 300,000 (slow PC so reduced loop count)
Gecko/20090914 Shiretoko/3.5.4pre
Result : 2401,4474,310,53,7,8
Gecko/20090915 Minefield/3.7a1pre
Result : 1690,1193,350,148,109,110
![]() |
||
Comment 1•14 years ago
|
||
This can also be seen in the dromaeo "getElementById (not in document)" test.
Should remeasure once we have the new DOM bindings.
Depends on: 622298
Updated•14 years ago
|
OS: Windows Vista → All
Hardware: x86 → All
Version: unspecified → Trunk
![]() |
||
Comment 2•12 years ago
|
||
Great news: Firefox is generally faster than Chrome! It's slower only on the first one.
Nightly 26: 241,99,15,8,9,4
Chrome 29: 159,360,186,12,11,12
![]() |
||
Comment 3•11 years ago
|
||
FWIW, attachment 400951 [details] somewhat regressed recently for the second result value (d3 - d2):
Firefox 31 (Aurora, CSet: b982a8afab52): 209, 95, 12, 7, 6, 6
Firefox 32 (Nightly, CSet: 00c2ba04f8d4): 231, 650, 12, 9, 7, 7
Chrome 37 : 134, 528, 208, 9, 10, 9
I tracked this down to
Last good revision: cbe4f69c2e9c (2014-05-27)
First bad revision: e017c15325ae (2014-05-28)
Pushlog:
https://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=cbe4f69c2e9c&tochange=e017c15325ae
and further
https://hg.mozilla.org/integration/mozilla-inbound/pushloghtml?fromchange=a3f2754fcfb8&tochange=79520ed7bc4e
=> by Bug 789261 (defaulting dom.window_experimental_bindings;true)
Comment 4•11 years ago
|
||
This bug is ancient. Please file new bugs for recent regressions.
![]() |
||
Comment 5•11 years ago
|
||
(In reply to Olli Pettay [:smaug] from comment #4)
> This bug is ancient. Please file new bugs for recent regressions.
Done per Bug 1022736.
![]() |
||
Comment 6•9 years ago
|
||
Nightly 48: 137,150,15,6,4,3
Chrome 49: 169,965,268,4,4,5
Would be nice to compare to Safari.
Safari
Loop Count : 1000,000
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17
27,119,154,37,8,9
26,120,150,37,7,8
26,117,150,36,8,8
26,119,149,39,9,7
27,116,151,37,7,8
26,119,149,36,8,8
26,116,153,37,7,8
26,119,151,37,7,8
26,116,149,37,8,8
26,115,154,38,7,8
Firefox
Loop Count : 1000,000
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:45.0) Gecko/20100101 Firefox/45.0
49,71,7,4,2,1
49,71,4,4,1,2
49,72,6,3,2,2
49,70,5,3,2,1
49,70,5,3,2,2
49,71,5,3,2,1
50,71,5,3,2,1
52,69,5,3,2,2
49,70,7,3,2,2
49,70,7,3,2,1
Assignee | ||
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
Updated•3 years ago
|
Severity: normal → S3
Comment 8•1 year ago
|
||
Chrome: https://share.firefox.dev/3XbkyJG (222ms)
Nightly: https://share.firefox.dev/3SV2u3W (100ms)
Calling this fixed.
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•