Opened 15 years ago
Closed 14 years ago
#7260 closed Bug (wontfix)
node.js -> getParents performance poor
| Reported by: | campaign | Owned by: | Garry Yao |
|---|---|---|---|
| Priority: | Normal | Milestone: | |
| Component: | Performance | Version: | 3.0 |
| Keywords: | Cc: |
Description (last modified by )
getParents : function( closerFirst )
{
var node = this;
var parents = [];
do
{
parents[ closerFirst ? 'push' : 'unshift' ]( node );
}
while ( ( node = node.getParent() ) )
return parents;
},
unshift method performance poor
example code
var t = +new Date,s = []
for(var i = 0;i<1000;i++){
s.push(i)
};
s.reverse();
alert(+new Date - t) // 2
var t = +new Date,s = []
for(var i = 0;i<1000;i++){
s.unshift(i)
};
alert(+new Date - t) //21
in ie8
Attachments (1)
Change History (8)
comment:1 Changed 15 years ago by
| Component: | General → Performance |
|---|
comment:2 Changed 15 years ago by
| Description: | modified (diff) |
|---|---|
| Keywords: | HasPatch added |
comment:3 Changed 15 years ago by
| Keywords: | HasPatch? added; HasPatch removed |
|---|---|
| Version: | 3.5.3 (SVN - trunk) → 3.0 |
comment:4 Changed 15 years ago by
| Owner: | set to Garry Yao |
|---|---|
| Status: | new → review |
Changed 15 years ago by
| Attachment: | 7260.patch added |
|---|
comment:6 Changed 15 years ago by
I've created a performance test that reflects our usage of it a bit better:
http://jsperf.com/array-push-vs-unshift
It shows that we'll have no real benefits on changing our code, but the theory can still be accepted (except for Opera).
comment:7 Changed 14 years ago by
| Keywords: | HasPatch? removed |
|---|---|
| Resolution: | → wontfix |
| Status: | review → closed |

Please enclose code into
codetags.